Post image on Facebook web - ios

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];

Related

How to share posts on Facebook and deep link to my iOS app

I'm trying to implement deep linking in my iOS app, so far I can post to my wall but only posts that are really links that goes to google.com (obviously this is a test link). I want the user to be navigated to my app when clicking on the post through the Facebook app, please I need a step by step guide cause Facebook documentation about its a little bit complicated. Here's my code:
- (void)shareOnFacebookWithName:(NSString *)contentTitle withDescription:(NSString *)contentDescription withLink:(NSString *)contentURL withPictureLink:(NSString *)imageURL andViewController:(UIViewController*)viewController{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:contentURL];
content.contentTitle = contentTitle;
content.imageURL = [NSURL URLWithString:imageURL];
content.contentDescription = contentDescription;
[FBSDKShareDialog showFromViewController:viewController
withContent:content
delegate:self];
}

Sharing a video with a caption using Facebook iOS SDK

I'm using the latest version of the Facebook SDK.
Sharing a photo with a caption is easy:
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImage:image userGenerated:YES];
photo.caption = txt_desc.text;
content.photos = #[photo];
[FBSDKShareAPI shareWithContent:content delegate:nil];
But the .caption property is not found on FBSDKShareVideo or FBSDKShareVideoContent. I have gone down the list for all the properties available to FBSDKShareVideo and FBSDKShareVideoContent but there's nothing that seems like it would hold the caption. The FB SDK documentation doesn't give any answers either.
I know it's possible to share a video with a caption on iOS because the Instagram iOS app does it. I just don't know how. Any one have any idea?
As you can read in the documentation for FBSDKShareVideo, it does not support providing a description/caption.

How make image sharing to Facebook with link back to content page in website/app like Instagram?

I am building an iOS app that let user created some type of images and when user finished doing that they can choose to publish it on their facebook timeline automatically.
I am able to post to user's timeline automatically because user allow publish_permission to our app. And I let my app post an image created by users to their facebook timeline. It went out smoothly. The image appear on Facebook and it displayed that this image is created by my app. But I am not able to provide the link when users click on the name of app to my content page. How can I do that ? I saw Instagram having this feature and it should drive more engagement to our app. This is the screenshot of how Instagram does this
This is how my app display it
This is the code how I posted image to user's timeline in my iOS app
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageWithData:,myImage];
photo.userGenerated = YES;
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.myWebsite.com/profile/%#/item/xxxx]];
photo.caption = [NSString stringWithFormat:#"%#%# Created by xxx"];
photo.userGenerated = YES;
photo.imageURL = URL;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
[FBSDKShareAPI shareWithContent:content delegate:self];
Do I need to use opengraph or anything else ? Please help.
Thanks in advance

Facebook share extension, sharing image and link

It seems Facebook has recently broken (or intentionally removed?) the ability to share images and links in one post via their share extension, trying to share an image with a link now results in only the image posting. Sharing only the link works and generates a post with an image preview of the linked page.
Previously you could share images and links in one post, is there a way to restore this functionality with the after Facebook app v29?
Here's a brief sample that illustrates what previously worked, but now only shares the image.
NSArray *activityItems = #[
[NSURL URLWithString:#"http://stackoverflow.com/"],
[UIImage imageNamed:#"shareImage"]
];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
Update
- Facebook has acknowledged this as a bug
As per Facebook latest SDK v4.0.1. we can surely share image and link but not both at same time.
Sharing URL Link and image URL (not Image):-
FBSDKShareLinkContent model includes attributes that show up in the post:
contentURL - the link to be shared
contentTitle - represents the title of the content in the link
imageURL - the URL of thumbnail image that appears on the post
contentDescription - of the content, usually 2-4 sentences
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://google.com"];
content.imageURL=[NSURL URLWithString:#"http://nasa.org/a.jpg"];
content.contentTitle=#"Facebook Share";
content.contentDescription=#"Lets see, How my share works guyz..";
[FBSDKShareDialog shareFromViewController:self
withContent:content
delegate:nil];
Sharing Only Image:-
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = self.imgView.image;// you can edit it by your choice
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];

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