iOS: FBSDKShareDialog Opening App but Not Allowing User to Share Link - ios

I'm trying to integrate the new Facebook SDK into an app I'm working on and for some reason whenever I try and share a link the share screen doesn't come up. I get kicked to the Facebook app (or the web app if there's no Facebook app installed), but I never get an option to share the link I'm trying to get the user to post.
I've pretty much followed the example on the Facebook developer site to a T, but for reference, here's my code:
- (IBAction)shareToFacebook:(id)sender {
NSLog(#"Share to Facebook");
FBSDKShareLinkContent *content = [FBSDKShareLinkContent new];
content.contentURL = [NSURL URLWithString:#"http://google.com"];
content.contentTitle = #"Test Post!";
content.contentDescription = #"Content Description;
FBSDKShareDialog *shareDialog = [FBSDKShareDialog new];
[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog setFromViewController:self];
[shareDialog show];
// [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];
}
As you can see above, I've tried using both the convenience method Facebook uses in their documentation, as well as being more verbose, but both produce the same result (opening the Facebook app but not giving the user an option to share any content). Any help at all would be greatly appreciated!

add to you code
[shareDialog setDelegate:self]
<FBSDKSharingDelegate> to your class
FBSDKSharing code
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary *)results {
NSLog(#"FB: SHARE RESULTS=%#\n",[results debugDescription]);
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(#"FB: ERROR=%#\n",[error debugDescription]);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(#"FB: CANCELED SHARER=%#\n",[sharer debugDescription]);
}
set break point in the didFailWithError and You can see many interesting underlying errors descriptions.

This this example for share image from application to facebook with using swift
func shareWithFacebook(){
let share : FBSDKShareLinkContent = FBSDKShareLinkContent()
share.imageURL = NSURL(string: "image url")
share.contentTitle = "content description "
share.contentURL = NSURL(string: "https://www.example.com")
let dialog : FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = share
let facebookURL = NSURL(string: "fbauth2://app")
if(UIApplication.sharedApplication().canOpenURL(facebookURL!)){
dialog.mode = FBSDKShareDialogMode.Native
}else{
dialog.mode = FBSDKShareDialogMode.FeedWeb
}
dialog.show()
}
Don't forgot to add facebook framework

As it states in the FBSDKShareDialogMode.h:
#discussion The automatic mode will progressively check the availability of different modes and open the most
appropriate mode for the dialog that is available.
So just choose another Share Dialog Mode.

It actually turned out to be a small typo in my info.plist for the app. Just a heads up to anyone else getting a similar error to check over all the information they have setup there and be sure it's all correct.

I had this problem on only one iPhone whereas in other iPhones it worked fine. It turned out that the Facebook app in that device was outdated and hence the FBSDKShareDialog wasn't showing up. Once the Facebook app was updated to the latest version, the FBSDKShareDialog started working fine.

try to use this mode:
dialog.mode = FBSDKShareDialogModeFeedWeb

To share on Facebook through Native iOS app.
We need updated FB SDK installed in app.
I used Pods to installed.
link to get pod set up into Mac: https://cocoapods.org
Write pod file name in podfile :
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
or
manual installation please follow : https://developers.facebook.com/docs/sharing/ios
after successful installation of FB SDKs.
Write code on button action:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://AppLink"];
content.quote = #"Sample description of app";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
It will automatically handle Native or Web (if not installed.)

Related

FBSDKSharingDelegate callbacks only work only with FBSDKShareDialogModeShareSheet - is this expected behaviour? [iOS 10 + 11]

I have been using code like this to share videos to Facebook:
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = assetURL;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video;
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = vc;
dialog.shareContent = content;
dialog.delegate = self;
dialog.mode = FBSDKShareDialogModeShareSheet;
if (![dialog canShow]) {
dialog.mode = FBSDKShareDialogModeNative;
if (![dialog canShow]) { dialog.mode = FBSDKShareDialogModeAutomatic; }
}
[dialog show]
where the delegate conforms to FBSDKSharingDelegate and implements these methods to track the result:
-(void)sharer:(id<FBSDKSharing>)sharerdidCompleteWithResults:(NSDictionary*)results;
-(void)sharer:(id<FBSDKSharing>)sharerdidFailWithError:(NSError*)error;
-(void)sharerDidCancel:(id<FBSDKSharing>)sharer;
I observe these callbacks working on iOS 10 for FBSDKShareDialogModeShareSheet, but in an otherwise identical implementation they are not called when using other dialog modes (for example) FBSDKShareDialogModeNative. In iOS 11, it doesn't appear that the share sheet mode is available anymore (presumably due to the Social Framework changes).
I don't have Facebook login in my app (nor any login), nor do I do anything to request FB permissions other than expect the user to authenticate within the native FB app. Is it expected that these callbacks will not execute in these other dialog modes, or is there something special I should do to get it them to work in this case?
The FB docs state
The delegate is notified with the results of the sharer as long as the
application has permissions to receive the information. For example,
if the person is not signed into the containing app, the sharer may
not be able to distinguish between completion of a share and
cancellation.
We are obviously passing the user to the native Facebook app in which they are authenticated - I'm not sure why this would work for one dialog mode and not for another. I'd rather not have to request the user login, as the whole point is to use the native FB app and let FB manage their own business internally.
Any help would be much appreciated. Thank you!

Facebook Deep Linking is not opening the app

I am sharing my post on Facebook. I am sharing Image, Content URL, Description. I am using this code for sharing:
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = APP_NAME;
content.contentDescription = text;
content.imageURL = [NSURL URLWithString:[[arrAllEvents valueForKey:#"flyer_image"]objectAtIndex:0]];
content.contentURL = url;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeFeedWeb;
[dialog show];
I have enable Deep Linking (News Feed links launch this app) option for https://developers.facebook.com.
I have added my Fbid and URLShema Like this
<key>CFBundleURLSchemes</key>
<array>
<string>abcevent://</string>
<string>fb1......</string>
</array>
and add code in appdelegate.m for the same like this
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url,NSError *error){
if([[url scheme] isEqualToString:#"abcevent"])
{
[self callNewsletter:url];
}
}];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[FBSDKAppEvents activateApp];
}
Now if I am sharing my post on fb via application. That post click is not opening my app in iPhone Deep linking is not working.
Can anyone tell what other things I am missing with this?
The fetchDeferredAppLink method only works with ads. It never worked with links shared organically on the News Feed. You can read about more limitations of deep linking from Facebook in this blog post, but there are two core things to know:
Facebook has never supported deferred deep linking for non-paid content.
Facebook's App Links standard at one point supported normal deep linking (meaning if the app is already installed), but this has been broken on iOS for a long time.
If you want this sort of functionality, you'll need a separate solution like Branch.io (full disclosure: I'm on the Branch team).

Post image on Facebook web

In my app, I am using SLComposeViewController to post images on Facebook app, which works fine. Requirement is, if the Facebook app is not installed, I would like to open the web page and allow user to post the image though web. Please anyone can advise how to post the image on Facebook web? I have iOS 9 and above with Xcode 8.1.
Use Facebook SDK for post image to facebook. You can find code and documentation here:
https://developers.facebook.com/docs/sharing/ios
Facebook SDK will handle all types of exception and scenario.
If Facebook app is not installed. but you FB accounts synced with setting app in your iPhone.
you can use below code to share the photo. But it will not open web browser.
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = img; // your image
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
To share via web browser, you can use below code.
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.imageURL = [NSURL URLWithString:img]; // image url
[FBSDKShareDialog showFromViewController:self.viewController
withContent:content
delegate:self];

How to share a post to a facebook group, not my own timeline, using the Facebook SDK share dialog?

I'm trying to share a link object to a Facebook group using the share dialog. No one seems to have answered this question satisfactorily yet.
The SDK documentation clearly states that you can use the share dialog to share to your own timeline or groups, yet I can't figure out how to do it. I also don't see any other apps that do it. Using the web share dialogue on a desktop you can see the option, but on a mobile website you don't! This screenshot of the iOS Facebook app shows what I'm talking about:
I'm trying to get the functionality in where it says 'tap to change' at the top.
It appears you have to use an instance of FBSDKShareDialog, and set the mode to FBSDKShareDialogModeNative.
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = viewController;
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.test.com"];
content.contentTitle = productItem.productTitle;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeNative;
if (![dialog canShow]) {
dialog.mode = FBSDKShareDialogModeWeb;
}
dialog.delegate = self;
[dialog show];

FBSDKShareDialog doesn't share Photo without Facebook App installed, IOS

I am using Facebook SDK 4.0,https://developers.facebook.com/docs/sharing/ios#share_dialog
I am using FBSDKShareDialog to share Photo.It does share Photo if user has installed Facebook app,
But it fails when user hasn't installed FB App. but they say "If someone doesn't have Facebook app installed it will automatically falls back to a web-based dialog."
Idk whats wrong please help me in sharing photo using FBSDK 4.0.
My code is
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = self.capturedImageView.image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
This is error report
error:"com.facebook.sdk:FBSDKErrorArgumentNameKey=shareContent,
com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Feed share dialogs
support FBSDKShareLinkContent."
FBSDKShareDialog only supports FBSDKShareLinkContent to post image or URL.So to use share Dialog you have to use FBSDKShareLinkContent.
You could use it as follows :
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.imageURL = [NSURL URLWithString:#"http://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg"];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
If you want to share a link then just use content.contentURL.
Refer to : https://developers.facebook.com/docs/sharing/ios#share_dialog
If you are using FBSDKSharePhoto then you need the native Facebook for iOS app installed.
Refer to :https://developers.facebook.com/docs/sharing/ios#photos
I also had the same issue as the documentation is also saying that they provide fallback mechanisms, which seems not true for this case:
Built-In Share Fallbacks
In past versions of the SDK for iOS, your app had to check for a
native, installed Facebook app before it could open the Share Dialog.
If the person didn't have the app installed, you had to provide your
own code to call a fallback dialog.
Now the SDK automatically checks for the native Facebook app. If it
isn't installed, the SDK switches people to their default browser and
opens the Feed Dialog. If someone wants to share an Open Graph story,
the SDK opens the Web Share Dialog.
First configure Facebook account of iOS device before and then use following code it will work:
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = self.capturedImageView.image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];

Resources