I try to shared image to Facebook and I need that the app name was be in the shared post in Facebook
this is the code :
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
UIImage *image1 = [GeneralMethods imageConvertToSizeWithImage:postImageView.image scaledToWidth:300];
photo.image = [UIImage imageNamed:@"VImage.png"];
photo.userGenerated = YES;
NSDictionary *properties = @{
@"og:type": @"article",
@"og:title": @"new item",
@"og:description": @"bla bla",
// @"og:image": @[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// [object setPhoto:photo forKey:@"og:image"];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Add the photo to the action. Actions
// can take an array of images.
[action setArray:@[photo] forKey:@"image"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
[FBSDKShareDialog showFromViewController:ParetDelaget withContent:content delegate:self];
this is Facebook preview page with the image i add:
this is the post in my Facebook wall without image :
whats I do wrong ?
Uncomment this line:
// @"og:image": @[photo],
And comment this one:
[action setArray:@[photo] forKey:@"image"];
Like this you will have both image, title and description showing.
A little remark: the photo object must be a string URL
In my case, here is the resulting code:
// Create an object
NSDictionary *properties = @{
@"og:type": @"article",
@"og:url": @"https://the_link_you_want.com",
@"og:title": @"your title",
@"og:description": @"your description",
@"og:image": @"http://url_to_your_image"
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"news.publishes";
[action setObject:object forKey:@"article"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
NSLog(@"FB Error: %@", error);
}
Hope that helps