IOS Facebook SDK 3 上传带有消息的图像 [英] IOS Facebook SDK 3 upload image with message

查看:16
本文介绍了IOS Facebook SDK 3 上传带有消息的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将图片上传到 Facebook 墙:

I am using the following code to upload an image to Facebook wall :

UIImage *img = [UIImage imageNamed:@"logoits.png"];

[FBRequestConnection startForUploadPhoto:img
                       completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

    NSLog(@"Facebook posting %@",result);
    NSLog(@"Facebook posting %@",error);

}];  

它按预期工作,但我想为这张上传的照片添加一条消息或标题,查看 FBRequestConnection 的文档,没有这样的例子.http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/

It works as expected but I would like to add a message or title to this uploaded photo, and looking at the documentation of FBRequestConnection there is no example of that. http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/

如何上传带有消息的图片?

How do I upload an image with message?

推荐答案

在 Facebook SDK 3.0 中,只能使用给定的方法发布图像,而对于其他操作,您需要使用图形 pi.

In the Facebook SDK 3.0 only a image can be post using the given methods, and for other actions you need to use graph a pi's.

因此,要发布带有消息的图像,您需要使用 graph-api.这是一行代码,可让您在用户时间轴上发布带有消息的图像.

So for post a image with message you need to use graph-api. Here is the line of codes which lets you to post a image with message on users timeline.

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"your custom message" forKey:@"message"];
[params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];
_shareToFbBtn.enabled = NO; //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
         [self alertWithTitle:@"Facebook" message:@"Unable to share the photo please try later."];
     } 
     else
     {
         //showing an alert for success
         [UIUtils alertWithTitle:@"Facebook" message:@"Shared the photo successfully"];
     }
     _shareToFbBtn.enabled = YES;
 }];

并确保只有在登录成功后才启用_shareToFbBtn.

and also make sure _shareToFbBtn is enabled only after login is success.

这篇关于IOS Facebook SDK 3 上传带有消息的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆