2012-07-23 70 views
0

我目前有以下代码,选择一个随机的Facebook朋友,并张贴到他们的墙上。我希望能够从所有朋友中选择(而不是随机选择一个)并发布到他们的墙上。如果有人能帮助我用下面的代码,这将是巨大的:)发布到Facebook的朋友墙而不是发送与iOS的通知

case gkAPIFriendsForDialogFeed: 
      { 
       NSArray *resultData = [result objectForKey: @"data"]; 
       // Check that the user has friends 
       if ([resultData count] > 0) { 
        // Pick a random friend to post the feed to 
        int randomNumber = arc4random() % [resultData count]; 
        [self apiDialogFeedFriend: 
        [[resultData objectAtIndex: randomNumber] objectForKey: @"id"]]; 
       } else { 
        [self showMessage:@"You do not have any friends to post to."]; 
       } 
       break; 
      } 

这个代码选择了所有的朋友,但不张贴到他们的墙上,而不是它发送一些通知:

case gkAPIGetAppUsersFriendsUsing: 
     { 
      NSMutableArray *friendsWithApp = [[NSMutableArray alloc] initWithCapacity:1]; 
      // Many results 
      if ([result isKindOfClass:[NSArray class]]) { 
       [friendsWithApp addObjectsFromArray:result]; 
      } else if ([result isKindOfClass:[NSDecimalNumber class]]) { 
       [friendsWithApp addObject: [result stringValue]]; 
      } 

      if ([friendsWithApp count] > 0) { 
       [self apiDialogRequestsSendToUsers:friendsWithApp]; 
      } else { 
       [self showMessage:@"None of your friends are using Whatto."]; 
      } 

      [friendsWithApp release]; 
      break; 
     } 

回答

1

获得随机ID后调用该函数。

并根据您的应用更改参数。

- (空)sendFBPost:(UIButton的*)标记

{

NSString *Message = [NSString stringWithFormat:@"-posted via iPhone App"]; 
NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           Message, @"message", nil]; 
NSString *post=[[appDelegate.FBFriendListArray objectAtIndex:tag.tag] objectForKey:@"id"]; 

[[appDelegate facebook] requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",post] andParams:params1 andHttpMethod:@"POST" andDelegate:self]; 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message!" message:@"Invitation Send Sucessfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
[alert show]; 
[alert release]; 

}

+0

是不是有一种方法来改变它,而不是挑选一个随机的朋友它显示所有?谢谢 – hanumanDev 2012-07-23 12:31:50

+0

我会为ObjectAtIndex的tag.tag放入什么?我需要用户能够从朋友列表中选择一个朋友。谢谢 :) – hanumanDev 2012-07-25 10:31:37

2

发帖对多用户的墙壁是反对Facebook平台条款。您应该坚持使用Requests方法,因为这是向多个用户发送消息的正确方法。

+0

我只需要选择一个朋友,并张贴到他们的墙上。一次没有很多朋友。只需从所有朋友中选择一个,然后张贴到他们的墙上。代码的第一部分是这样做的,但它显示了一个随机的朋友。我希望能够从列表中选择一个朋友 - 就像我在上面发布的第二个代码块中那样。谢谢:) – hanumanDev 2012-07-23 11:42:40

+0

在这种情况下,你需要建立一个视图,加载朋友的列表并让用户选择要发布的朋友。 – 2012-07-23 11:45:11

+0

我已经有了。唯一的问题是它只是发送通知而不是Wall帖子。这就是我需要弄清楚的。 – hanumanDev 2012-07-23 11:52:02

相关问题