Ben*_*Ben 16 facebook-graph-api ios
我使用以下代码将图像上传到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);
}];
Run Code Online (Sandbox Code Playgroud)
它按预期工作,但我想为这个上传的照片添加一条消息或标题,并查看FBRequestConnection的文档,没有这样的例子.http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/
如何上传带有消息的图像?
vis*_*shy 45
在Facebook SDK 3.0中,只有图像可以使用给定的方法发布,而对于其他操作,您需要使用图形pi.
因此,要发布带有消息的图像,您需要使用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;
}];
Run Code Online (Sandbox Code Playgroud)
并且_shareToFbBtn只有在登录成功后才能确保启用.
linesvishy的解决方案效果很好,值得注意的是,如果您使用的是Facebook SDK 3.1并且使用了方法
FBRequest *request = [FBRequest requestForUploadPhoto:_imageToShare];
Run Code Online (Sandbox Code Playgroud)
您可以使用以下行替换它:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:_textToShare forKey:@"message"];
[params setObject:_imageToShare forKey:@"picture"];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"];
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!快乐的编码!
| 归档时间: |
|
| 查看次数: |
17489 次 |
| 最近记录: |