2012-07-23 73 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

相關問題