使用FBDialog上传UIImage

时间:2012-06-13 08:09:27

标签: objective-c ios facebook facebook-ios-sdk

我想使用Facebook SDK中的FBDialog,但似乎只需要一个用于发布图片的网址。有没有办法在发布之前使用UIImageFBDialog上传到Facebook,而无需将图片上传到其他服务器?

我目前正在使用此功能在Facebook上发布UIImage

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"A caption", @"caption",
                               nil];
[_facebook requestWithMethodName:@"photos.upload" andParams:params andHttpMethod:@"POST" andDelegate:nil];

效果很好,但我需要FBDialog。有没有办法用FBDialog做同样的事情?

感谢任何帮助。

3 个答案:

答案 0 :(得分:2)

不,要发布UIImage,您无法直接附加它。这有两种方法:

  1. 过于上传到服务器,然后将URL /请求/查询带到该服务器
  2. (更实用的方法)上传到您的Facebook用户的相册,然后发布该图片
  3. 有关更深入的教程,请查看此链接:

    Official Facebook iOS Tutorial

    This is a similar question with a great answer that provides step by step tutorial

答案 1 :(得分:2)

从Facebook iOS SDK v3.13 +开始,您可以presentShareDialogWithPhotoParams直接从设备上传图片。请参阅以下示例代码:

FBShareDialogPhotoParams *photoParams = [FBShareDialogPhotoParams new];
UIImage *screenshot = //image you want to share.
photoParams.photos = @[screenshot];
[FBDialogs presentShareDialogWithPhotoParams:photoParams
                                 clientState:nil
                                     handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {

                                     }];

答案 2 :(得分:1)

- (void) feedDialogButtonClicked {
NSMutableDictionary *params = 
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
        @"Testing Feed Dialog", @"name",
        @"Feed Dialogs are Awesome.", @"caption",
        @"Check out how to use Facebook Dialogs.", @"description",
        @"http://www.example.com/", @"link",
        @"http://fbrell.com/f8.jpg", @"picture",
        nil];  
[facebook dialog:@"feed"
        andParams:params
      andDelegate:self];

}

来自官方Facebook iOS教程,由Rohan发布