Reputation: 60
I am trying to share a graphobject on facebook but i'm encountering some problems when i add the image.
Here is my current code:
// Construct an FBSDKSharePhoto
UIImage* psImg = [UIImage imageNamed:@"fb_share_logo"];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = psImg;
photo.userGenerated = NO;
NSDictionary *properties = @{@"og:type": @"my_obj",
@"og:title": @"Title",
@"og:description": @"Description",
@"og:web": @"http://www.mywebssite.com"
// @"og:image": @[photo]
};
//create GraphObject from properties
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
//create action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"my_action" object:object key:@"my_key"];
//create content
FBSDKShareOpenGraphContent *content = [FBSDKShareOpenGraphContent new];
//set content action
content.action = action;
content.previewPropertyName = @"my_prop_type";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
if (![shareDialog canShow]) {
// update the app UI accordingly
NSLog(@"is showing");
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
// check the error for explanation of invalid content
NSLog(@"error");
}
if([shareDialog canShow]){
[shareDialog show];
}
If i don't add the image it works and the dialog shows but i need it. If i add the image i get this:
Upvotes: 1
Views: 249
Reputation: 36
The mode parameter for shareDialog is not set in your code.
So first of all you need to set it as follows (more details here):
dialog.mode = FBSDKShareDialogModeNative; // to open native app
if (![dialog canShow]) {
// if there is no FB app installed on that device, use browser
dialog.mode = FBSDKShareDialogModeFeedBrowser;
}
And if you still cannot open the share dialog, you should check your Info.plist file for LSApplicationQueriesSchemes key and see if it set as follows (developers.facebook):
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
Upvotes: 2