我正在使用以下代码将图像上传到 Facebook 墙:
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/
如何上传带有消息的图片?
最佳答案
在 Facebook SDK 3.0 中,只能使用给定的方法发布图像,对于其他操作,您需要使用 graph a pi's。
因此,要发布带有消息的图像,您需要使用 graph-api。这是一行代码,可让您在用户时间轴上发布带有消息的图像。
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
。
关于IOS Facebook SDK 3 上传带消息的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12607473/