presentFeedDialogModallywithSession不发布消息给朋友

时间:2013-06-27 11:59:05

标签: ios facebook

我使用以下代码在朋友的Facebook墙上发布消息。此代码将消息发布到登录用户墙,但不会发布到朋友的墙上

Iam还给出了“to”值,即朋友的脸书ID(116623456)和App_id,但同样的问题仍然存在。

请提供一个很好的指导。

- (void)facebookViewControllerDoneWasPressed:(id)sender   
 {
       NSLog(@"DonePressed Called");
       NSString* fid;
       NSString* fbUserName;

       NSString *message = [NSString stringWithFormat:@"You have been selected as a       health coach(Multiple Users1), You will be receiving daily and weekly reports from here on!!!!"];


       NSLog(@"Before For");

//   NSString *SelectedFriends = nil;
for (id<FBGraphUser> user in _friendPickerController.selection)
{

    fid = user.id;
    fbUserName = user.name;


     NSLog(@"User Name =%@, USer id =%@",fbUserName, fid);


}
NSLog(@"After For");
NSLog(@"%@",fid);

NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"4444444444444444",@"app_id",
fid,@"to",
nil];
// Invoke the dialog


[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:
 ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
     if (error) {
         // Error launching the dialog or publishing a story.
         NSLog(@"Error publishing story.");
     } else {
         if (result == FBWebDialogResultDialogNotCompleted) {
             // User clicked the "x" icon
             NSLog(@"User canceled story publishing.");
         } else {
             // Handle the publish feed callback
             NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
             if (![urlParams valueForKey:@"post_id"]) {
                 // User clicked the Cancel button
                 NSLog(@"User canceled story publishing.");
             } else {
                 // User clicked the Share button
                // Show the result in an alert
                [[[UIAlertView alloc] initWithTitle:@"Result"
                                             message:@"Message Posted Successfully"
                                            delegate:self
                                   cancelButtonTitle:@"OK!"
                                   otherButtonTitles:nil]
                  show];


             }
         }
     }
 }];

}

1 个答案:

答案 0 :(得分:0)

- (void)facebookViewControllerDoneWasPressed:(id)sender {
    NSMutableString *text = [[NSMutableString alloc] init];

    // we pick up the users from the selection, and create a string that we use to update the text view
    // at the bottom of the display; note that self.selection is a property inherited from our base class
    for (id<FBGraphUser> user in self.friendPickerController.selection) {
        if ([text length]) {
            [text appendString:@", "];
        }
        [text appendString:user.name];

        NSString *fid=user.id;
        NSString *fbUserName=user.name;

        NSLog(@"");

        NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Test miLineup!", @"message", @"Iphone Apps", @"name", nil];

        NSLog(@"\nparams=%@\n", params);

        //Post to friend's wall.
        [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed", fid] parameters:params HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
         {
             //Tell the user that it worked.
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Shared"
                                                                 message:[NSString stringWithFormat:@"Invited %@! error=%@", fbUserName, error]
                                                                delegate:nil
                                                       cancelButtonTitle:@"OK"
                                                       otherButtonTitles:nil];
             [alertView show];
         }
         ];

        //Close the friend picker.
        //[self dismissModalViewControllerAnimated:YES];
  }