2012-10-06 38 views
2

我可以用下面張貼在用戶牆圖片: -留言給朋友牆IOS SDK 3.0

if (appDelegate.session.isOpen) 
    { 
     FBSession.activeSession = appDelegate.session;    
     [FBRequestConnection startForUploadPhoto:img 
           completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
            [self showAlert:@"eCard Posted" result:result error:error]; 
           }]; 

    } 

現在的要求是選擇來自朋友選擇器類的朋友,並張貼在圖像上選擇朋友牆/時間表。

我已經集成了朋友選擇器類,如下所示: -

if (appDelegate.session.isOpen) 
    { 
     FBSession.activeSession = appDelegate.session; 
     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 presentModalViewController:self.friendPickerController animated:YES]; 


    } 

現在在委託方法: -

- (void)facebookViewControllerDoneWasPressed:(id)sender { 

// 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 
//UIImage *img = self.image; 
    FBSession.activeSession = appDelegate.session; 

for (id<FBGraphUser> user in self.friendPickerController.selection) { 

    FBSession.activeSession = appDelegate.session; 
    if (appDelegate.session.isOpen) 
    {    
     NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init]; 
     // [postVariablesDictionary setObject:@"me" forKey:@"name"]; 
     // [postVariablesDictionary setObject:self.image forKey:@"picture"]; 
     [postVariablesDictionary setObject:@"Sample Text" forKey:@"message"]; 
     NSLog(@"%@",user.id); 
     [FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"%@/feed",user.id] graphObject:[NSDictionary dictionaryWithDictionary:postVariablesDictionary] completionHandler:nil]; 


    }  
    else 
    { 
     if (appDelegate.session.state != FBSessionStateCreated) { 
      // Create a new, logged out session. 
      appDelegate.session = [[FBSession alloc] init]; 
     }    
     // if the session isn't open, let's open it now and present the login UX to the user 
     [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                 FBSessionState status, 
                 NSError *error) { 
     }]; 
    } 

} 

[self dismissModalViewControllerAnimated:YES]; 

}

上述委託方法總是導致錯誤代碼= 5 facebook sdk錯誤。應該調用什麼API來使上述圖像在選定的朋友牆上發佈。

請幫我.......

回答

1

最後我能夠在朋友的牆後的圖像。

委託方法作如下修改: -

- (void)facebookViewControllerDoneWasPressed:(id)sender { 

// 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 
//UIImage *img = self.image; 
FBSession.activeSession = appDelegate.session; 
if (appDelegate.session.isOpen) 
{    
    [FBSession openActiveSessionWithPermissions:[NSArray arrayWithObjects:@"publish_stream",@"user_photos",@"", nil] 
            allowLoginUI:NO 
           completionHandler:^(FBSession *session, 
                FBSessionState status, 
                NSError *error) { 

            if (error) { 
             NSLog(@"error"); 
            } else { 
             [FBSession setActiveSession:appDelegate.session]; 
            } 
           }]; 


    for (id<FBGraphUser> user in self.friendPickerController.selection) { 


     if (appDelegate.session.isOpen) 
     {  

      FBSession.activeSession = appDelegate.session; 
      NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init]; 
      [postVariablesDictionary setObject:self.image forKey:@"source"]; 
      // [postVariablesDictionary setObject:UIImagePNGRepresentation(self.image) forKey:@"source"]; 
      [postVariablesDictionary setObject:@"my image" forKey:@"message"]; 
      NSLog(@"%@",user.id); 
      [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",user.id] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
       [self showAlert:@"eCard Posted" result:result error:error]; 
      }]; 
     }  
     else 
     { 
      if (appDelegate.session.state != FBSessionStateCreated) { 
       // Create a new, logged out session. 
       appDelegate.session = [[FBSession alloc] init]; 
      }    
      // if the session isn't open, let's open it now and present the login UX to the user 
      [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                  FBSessionState status, 
                  NSError *error) { 
      }]; 
     } 

    } 

} 
[self dismissModalViewControllerAnimated:YES]; 

}

重視和感謝....

+0

上面的代碼工作? – user23790

+0

是的。在Facebook IOS SDK 3.0中。 – Sanjay