我想与 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"];
代码运行良好。
那行有什么问题。
我也想添加图像。