我想与Url,标题,标题和消息共享图像。我正在使用Facebook连接来做到这一点。在成功登录facebook后,我使用以下代码来共享图像。
NSLog(@"card image = %@",[MyClass getcardImage]);
// This log gives me an image object like <UIImage: 0x1f32d450>
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
nil];
[params setObject:@"An Image" forKey:@"name"];
[params setObject:[MyClass getCardURL] forKey:@"link"];
[params setObject:@"My Image" forKey:@"caption"];
[params setObject:@"Sharing myImage" forKey:@"message"];
[params setObject:UIImagePNGRepresentation([MyClass getcardImage]) forKey:@"picture"];
[params setObject:@"Hey! I am sharing my picture" forKey:@"description"];
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
} else {
alertText = [NSString stringWithFormat:
@"Posted action, id: %@",
result[@"id"]];
}
我收到error: domain = com.facebook.sdk, code=5
但是当我从params字典中删除以下行时,
[params setObject:UIImagePNGRepresentation([MyClass getcardImage]) forKey:@"picture"];
代码运作良好。
那条线路有什么不对。
我也想添加图片。
答案 0 :(得分:1)
“me / feed”端点仅接受“picture”参数的网址,而不接受图片数据。
请参阅https://developers.facebook.com/docs/reference/api/user/#posts
因此,您应该只为图像添加网址,而不是图像本身。