I am trying to set up Facebook sharing with FBSDK in my iOS app.
I have been reading the documentation here, and currently have
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
working with a content object - FBSDKShareLinkContent
.
However, upon trying to use the similar method as specified for Facebook Messenger sharing,
[FBSDKMessageDialog showWithContent:content delegate:self];
i am getting a crash. I caught the error and logged it in one of the delegate methods, and it states "The operation couldn’t be completed. (com.facebook.sdk.share error 202.) "
I have searched for this specific error but have not found anything directly with the same error. Here is full code
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:kAPPShareLink];
content.contentDescription = kAPPShareDescription;
content.contentTitle = kAPPShareTitle;
if (buttonIndex == 0) {
// Facebook
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
} else if (buttonIndex == 1) {
// Facebook Messenger
[FBSDKMessageDialog showWithContent:content delegate:self];
}
Forgive me if i am missing something obvious, but as this documentation reads, i assume the FBSDKMessageDialog showWithContent:
method would work the same way as FBSDKShareDialog showFromViewController:
which is working for me.
I had to login and then Post , that is how it worked :
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"https://developers.facebook.com/"];
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
messageDialog.delegate = self;
[messageDialog setShareContent:content];
if ([messageDialog canShow])
{
[messageDialog show];
}
else
{
// Messenger isn't installed. Redirect the person to the App Store.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/en/app/facebook-messenger/id454638411?mt=8"]];
}
}
}];
and the Share Delegate :
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(@"didCompleteWithResults");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError ::: %@" , error);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(@"sharerDidCancel");
}
Edit:
[messageDialog canShow] returns NO on the iPad, works fine on iPhone
Posted the issue on Facebook Developers forum.
I was stuck with this for a while and in the end realised that I had not added fb-messenger-share-api
under LSApplicationQueriesSchemes
in the info.plist
file. Just putting this here in case it helps someone. Thanks :)
N.B. It is
fb-messenger-share-api
and notfb-messenger-api
.
Note: This fits more as a comment, but I don't have enough reputation yet to post comments
I get the same error, both Facebook and messenger are updated.
I checked my permissions with
[[FBSDKAccessToken currentAccessToken] permissions]
and I think I have enough:
"contact_email",
"publish_stream",
"user_likes",
"publish_checkins",
"video_upload",
"create_note",
"basic_info",
"publish_actions",
"public_profile",
"photo_upload",
"status_update",
email,
"user_friends",
"share_item"
I tried the same way as OP, and also I tried that:
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
[messageDialog setShareContent:content];
messageDialog.delegate = self;
if ([messageDialog canShow]) {
[messageDialog show];
}
[messageDialog canShow]
returns NO, and the delegate methods catch the fail with the 202 error described by the OP.
I tried using the FBSDKSendButton, and doesn't seem to work either.
On the other hand, FBSDKShareDialog works perfectly...
I hope this helps to solve the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With