2012-05-31 49 views
8
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
           photoDescription, @"message", 
           image, @"image", 
           nil]; 


[facebook requestWithGraphPath:@"me/photos" 
            andParams:params 
           andHttpMethod:@"POST" 
            andDelegate:self]; 

这是我上传图片到Facebook所做的。该图像已成功上传到FaceBook'照片'。但我想将图像发布到我的FaceBook Feed。所以我试了,iPhone在Facebook上发布图片

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

但它仍然是发布到'照片'的图像。它不会出现在饲料...

我搜索,用不同的方法解决的办法,但我无法找到任何有用的......

回答

1

不知道你params是什么样子,但这种尝试..

UIImage *image = ...// some image. 

NSData *imageData= UIImagePNGRepresentation(image); 

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
          @"some message", @"message", imageData,@"source", nil]; 

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

我相信这是相同的问题解决方案。换句话说,它只会发布到用户时间线,而不是新闻提要。 –

+0

编辑我的答案,利用Facebook的对话方法,而不是图形请求。现在无法测试,但希望这就是答案 – skram

+0

我刚刚尝试过您的解决方案,但并未将该图像发布到Facebook。我认为'feed'对话框也是正确的。我也试过'我/饲料'哪个也没用。 –

0
UIImage* image=...; 
if ([FBSession.activeSession.permissions 
     indexOfObject:@"publish_actions"] == NSNotFound) { 

     NSArray *permissions = 
     [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil]; 
     [[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends 
               completionHandler:^(FBSession *session, NSError *error) {}]; 
    } 
    else 
    { 
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init]; 
    [params setObject:@"Photo post test..." forKey:@"message"]; 
    [params setObject:UIImagePNGRepresentation(image) forKey:@"picture"]; 
    //for not allowing multiple hits 

     [FBRequestConnection startWithGraphPath:@"me/photos" 
           parameters:params 
           HTTPMethod:@"POST" 
          completionHandler:^(FBRequestConnection *connection, 
               id result, 
               NSError *error) 
    { 
     if (error) 
     { 
      //showing an alert for failure 
      UIAlertView *alertView = [[UIAlertView alloc] 
             initWithTitle:@"Post Failed" 
             message:error.localizedDescription 
             delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
      [alertView show]; 

     } 
     else 
     { 
      //showing an alert for success 
      UIAlertView *alertView = [[UIAlertView alloc] 
             initWithTitle:@"Post success" 
             message:@"Shared the photo successfully" 
             delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
      [alertView show]; 

     } 
    }]; 
    }