2011-01-06 78 views
5

我想在用戶朋友牆上張貼一些東西。如何使用Facebook Graph API for iPhone發佈到朋友牆

我使用它來發布到用戶牆上

SBJSON *jsonWriter = [[SBJSON new] autorelease]; 

    NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys: 
                  @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil]; 

    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks]; 
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys: 
           @"a long run", @"name", 
           @"The Facebook Running app", @"caption", 
           @"it is fun", @"description", 
           @"http://itsti.me/", @"href", nil]; 
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment]; 
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"Share on Facebook", @"user_message_prompt", 
            actionLinksStr, @"action_links", 
            attachmentStr, @"attachment",nil]; 

    [facebook dialog:@"feed" 
      andParams:params 
      andDelegate:self]; 

但我需要在我的朋友牆上張貼。我怎麼能這樣做

在這post他們提到了關於targetId我必須做些什麼。

+0

仍然沒有回答:(有人答我的問題.. – iPrabu 2011-01-19 14:05:49

+0

23天走了,沒有答案... – iPrabu 2011-01-30 11:06:18

回答

3

您是否嘗試過使用,

[facebook requestWithGraphPath:@"[friend_ID]/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 

UPDATE:

張貼在牆上的朋友將不再與圖形API的工作。相反,你必須使用FBDialog。

0

@mAc

您必須先向Facebook授權。然後你實現'FBRequestDelegate'方法給你的班級。然後,讓與圖形API的請求之下

[facebook requestWithGraphPath:@"/me/friends" andDelegate:self]; 

一旦你的請求成功給出,API將調用委託方法「requestDdidLoad」,

-(void)request:(FBRequest *)request didLoad:(id)result { 

    NSLog(@"Result: %@", result); 

} 

形式的結果,你會得到frieds頁ID

0
- (IBAction)InviteAction:(id)sender // Button action 
{ 
    if (!FBSession.activeSession.isOpen) { 
     // if the session is closed, then we open it here, and establish a handler for state changes 
     [FBSession openActiveSessionWithReadPermissions:nil 
              allowLoginUI:YES 
             completionHandler:^(FBSession *session, 
                  FBSessionState state, 
                  NSError *error) { 
              if (error) { 
               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Invite friends process cancelled" 
                            message:nil 
                           delegate:nil 
                         cancelButtonTitle:@"OK" 
                         otherButtonTitles:nil]; 
               [alertView show]; 
              } else if (session.isOpen) { 
               [self InviteAction:sender]; 
              } 
             }]; 
     return; 
    } 

    if (self.friendPickerController == nil) { 
     // Create friend picker, and get data loaded into it. 
     self.friendPickerController = [[FBFriendPickerViewController alloc] init]; 
     self.friendPickerController.title = @"Pick Friends"; 
     self.friendPickerController.delegate = self; 
    } 

    [self.friendPickerController loadData]; 
    [self.friendPickerController clearSelection]; 

    [self presentViewController:self.friendPickerController animated:YES completion:nil]; 
} 

- (void) performPublishAction:(void (^)(void)) action 
{ 
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) 
    { 
     [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"] 
               defaultAudience:FBSessionDefaultAudienceFriends 
              completionHandler:^(FBSession *session, NSError *error) { 
               if (!error) { 
                action(); 
               } else if (error.fberrorCategory != FBErrorCategoryUserCancelled){ 
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied" 
                             message:@"Unable to get permission to post" 
                             delegate:nil 
                           cancelButtonTitle:@"OK" 
                           otherButtonTitles:nil]; 
                [alertView show]; 
               } 
              }]; 
    } else { 
     action(); 
    } 

} 



- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
          user:(id<FBGraphUser>)user 
{ 
    self.loggedInUser = user; 
} 


- (void)facebookViewControllerDoneWasPressed:(id)sender 
{ 
    NSMutableString *text = [[NSMutableString alloc] init]; 
    for (id<FBGraphUser> user in self.friendPickerController.selection) 
    { 

     if ([text length]) { 
      [text appendString:@","]; 
     } 
     [text appendString:[NSString stringWithFormat:@"%@",user.id]]; 
    } 

    //For post to friend's wall 
    NSDictionary *params = @{ 
          @"name" : @"Hello Please checkout this app", 
          @"caption" : @" IOS APP", 
          @"description" : @"", 
          @"picture" : @"[email protected]", 
          @"link" : @"http:www.google.com", 
          @"to":text, 

          }; 


    // Invoke the dialog 
    [FBWebDialogs presentFeedDialogModallyWithSession:nil 
              parameters:params 
              handler: 
    ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
     if (error) { 
      NSLog(@"Error publishing story."); 
      UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to Post" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
      [alertshow show]; 
     } else { 
      if (result == FBWebDialogResultDialogNotCompleted) 
      { 
       NSLog(@"User canceled story publishing."); 
       UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to post on your friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
       [alertshow show]; 
      } else { 
       NSLog(@"Story published."); 
       UIAlertView *alertshow = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Posted on Friend wall" delegate:Nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
       [alertshow show]; 
      } 
     }}]; 



    [self fillTextBoxAndDismiss:text.length > 0 ? text : @"<None>"]; 
} 

- (void)facebookViewControllerCancelWasPressed:(id)sender { 
    [self fillTextBoxAndDismiss:@"<Cancelled>"]; 
} 

- (void)fillTextBoxAndDismiss:(NSString *)text 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
相關問題