如何使用FBRequestConnection将带有文本的图像上传到Facebook?

时间:2012-10-15 11:44:49

标签: objective-c facebook ios6

我正在尝试使用FBRequestConnection上传带有图片的文字,如下所示,但我只能上传文字,而不能上传图片。 但当我给任何图像链接代替img1(图像),然后我能够在Facebook墙上看到图像。

UIImage *img1 = [UIImage imageNamed:@"Default@2x.png"];

 NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                @"https://developers.facebook.com/ios", @"link",
                               img1, @"picture",
                               @"Facebook SDK for iOS", @"name",
                               @"build apps.", @"caption",
                               @"imagae description.", @"description",
                               nil]; 


[params setObject:@"post message" forKey:@"message"];


[FBRequestConnection
 startWithGraphPath:@"me/feed"
 parameters:params
 HTTPMethod:@"POST"
 completionHandler:^(FBRequestConnection *connection,
                     id result,
                     NSError *error) {
     NSString *alertText;
     if (error) {
         alertText = [NSString stringWithFormat:
                      @"error: domain = %@, code = %d",
                      error.domain, error.code];
     } else {
         alertText = @"Posted successfully.";
     }
     // Show the result in an alert
     [[[UIAlertView alloc] initWithTitle:@"Result"
                                 message:alertText
                                delegate:self
                       cancelButtonTitle:@"OK!"
                       otherButtonTitles:nil]
      show];
 }];

我已取得两项许可 @“publish_actions”,@“user_photos”

请在此代码中告诉我错误的地方。

2 个答案:

答案 0 :(得分:4)

IOS Facebook SDK 3 upload image with message

中查看我的答案

这是您所需要的类似方式。只需根据您的要求添加更多参数。

答案 1 :(得分:2)

将@“picture”更改为@“source”。 如果您使用新的Facebook 3.1 SDK,可以更简单:

FBRequest *req = [FBRequest requestForUploadPhoto:img1];
[req.parameters addEntriesFromDictionary:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"post message", @"message", nil]];

FBRequestConnection *con = [[FBRequestConnection alloc] init];
[con addRequest:req completionHandler....