Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用IOS SDK 3.0发布到好友墙_Ios_Image_Facebook Graph Api_Posting - Fatal编程技术网

使用IOS SDK 3.0发布到好友墙

使用IOS SDK 3.0发布到好友墙,ios,image,facebook-graph-api,posting,Ios,Image,Facebook Graph Api,Posting,我可以通过以下方式在用户墙上发布图像:- if (appDelegate.session.isOpen) { FBSession.activeSession = appDelegate.session; [FBRequestConnection startForUploadPhoto:img completionHandler:^(FBRequestConnectio

我可以通过以下方式在用户墙上发布图像:-

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];
                               }];

    }
现在的要求是从friend picker类中挑选朋友,并将图像张贴在选定的朋友墙上/时间线上

我集成了Friends picker类,如下所示:-

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];
-(void)按下FaceBookViewControllerDone:(id)发件人{
//我们从选择中选择用户,并创建一个字符串,用于更新文本视图
//请注意self.selection是从基类继承的属性
//UIImage*img=self.image;
FBSession.activeSession=appDelegate.session;
对于(self.friendPickerController.selection中的id用户){
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:@“示例文本”forKey:@“消息”];
NSLog(@“%@”,user.id);
[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@“%@/feed”,user.id]graphObject:[NSDictionary Dictionary Dictionary WithDictionary:postVariablesDictionary]completionHandler:nil];
}    
其他的
{
if(appDelegate.session.state!=FBSessionStateCreated){
//创建一个新的注销会话。
appDelegate.session=[[FBSession alloc]init];
}            
//如果会话未打开,让我们现在打开它并向用户展示登录UX
[appDelegate.session openWithCompletionHandler:^(FBSession*会话,
FBSessionState状态,
N错误*错误){
}];
} 
}
[自我解散Modalviewcontrolleranimated:是];
}

上述委托方法始终导致错误代码=5错误。应该调用什么API才能将上述图像发布到选定的好友墙中


请帮助我……

最后,我可以在朋友的墙上张贴图片了

委托方法修改如下:---

- (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];
-(void)按下FaceBookViewControllerDone:(id)发件人{
//我们从选择中选择用户,并创建一个字符串,用于更新文本视图
//请注意self.selection是从基类继承的属性
//UIImage*img=self.image;
FBSession.activeSession=appDelegate.session;
if(appDelegate.session.isOpen)
{            
[FBSession openActiveSessionWithPermissions:[NSArray arrayWithObjects:@“发布流”,“用户照片”,“无]
阿洛洛洛吉努伊:没有
completionHandler:^(FBSession*会话,
FBSessionState状态,
N错误*错误){
如果(错误){
NSLog(@“错误”);
}否则{
[FBSession setActiveSession:appDelegate.session];
}
}];
对于(self.friendPickerController.selection中的id用户){
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:@“我的图像”forKey:@“消息”];
NSLog(@“%@”,user.id);
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@“%@/photos”,user.id]参数:postVariablesDictionary HTTPMethod:@“POST”completionHandler:^(FBRequestConnection*连接,id结果,NSError*错误){
[自显示警报:@“eCard已发布”结果:结果错误:错误];
}];
}    
其他的
{
if(appDelegate.session.state!=FBSessionStateCreated){
//创建一个新的注销会话。
appDelegate.session=[[FBSession alloc]init];
}            
//如果会话未打开,让我们现在打开它并向用户展示登录UX
[appDelegate.session openWithCompletionHandler:^(FBSession*会话,
FBSessionState状态,
N错误*错误){
}];
} 
}
}
[自我解散Modalviewcontrolleranimated:是];
}


尊敬并感谢……

是的,在Facebook IOS SDK 3.0中。