I want to share an image with Url, title, caption and message. I am using Facebook connect to do that. After successful facebook login I am using the following code to share the image.
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"]];
}
I get error message like error: domain = com.facebook.sdk, code=5
But when I just remove the following line from params dictionary,
[params setObject:UIImagePNGRepresentation([MyClass getcardImage]) forKey:@"picture"];
The code works well.
Whats wrong in that line.
I want to add image as well.
The "me/feed" endpoint only accepts urls for the "picture" parameter, and not the image data.
See https://developers.facebook.com/docs/reference/api/user/#posts
So you should only include a url to an image, but not the image itself.