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

查看:92
本文介绍了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天全站免登陆