Share an image from my app to facebook - ios

I have a movie quiz app, and I want users to share the movie scene image that they are stuck on to Facebook so they can ask their friends for help.
With Facebook's recent changes I am struggling to figure out how to post the image that the user is up to.
All the movie scene images are stored in the app so there is no URL.
I am trying to get the image from my array like this:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.imageURL = [NSURL fileURLWithPathComponents:[[mainInfoArray objectAtIndex:index] objectForKey:PHONE_IMAGE]];
but it does not work.
Any ideas please to get this to work?
Thank You

First, you create the content, then you create a share-button with that content.
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
FBSDKShareButton *button = [[FBSDKShareButton alloc] init];
button.shareContent = content;
[self.view addSubview:button];

Related

FBSDKShareLinkContent without deep linking to app

I'm using FBSDKShareLinkContent to display a dialog to share a link to Facebook. No matter the link I use (I even tried with https://google.com/) when the post / link is tapped in the Facebook app my app is launched.
I want, however, to load the link in a web browser or the FB browser instead (and not have it launch my app or navigate to the app store). Is there anyway to achieve this? I tried both FBSDKShareDialogModeFeedWeb and FBSDKShareDialogModeAutomatic.
Here is my current code:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://google.com/"];
FBSDKShareDialog* dialog = [[FBSDKShareDialog alloc] init];
dialog.mode = FBSDKShareDialogModeFeedWeb;
dialog.shareContent = content;
dialog.fromViewController = self;
[dialog show];
Add this to your code:
FBSDKShareLinkContent *content1 = [[FBSDKShareLinkContent alloc] init];
content1.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
content1.contentTitle=#"Share";
[FBSDKShareDialog showFromViewController:self withContent:content1 delegate:nil];

Local UIImage not show in open graph story Facebook

I'm try to publish a local photo in a Facebook open graph story, but the image is not appears.
This code is the same of the documentation page of Facebook developers. facebook_developers open graph ios
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:#"coffee-and-sunrise.jpg"];
// Optionally set user generated to YES only if this image was created by the user
// You must get approval for this capability in your app's Open Graph configuration
// photo.userGenerated = YES;
// Create an object
NSDictionary *properties = #{
#"og:type": #"books.book",
#"og:title": #"A Game of Thrones",
#"og:description": #"In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.",
#"books:isbn": #"0-553-57340-3",
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"books.reads";
[action setObject:object forKey:#"books:book"];
// 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 = #"books:book";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
Facebook is aware this is broken on iOS and has marked it as "won't fix". Incredibly agitating, please do voice your concern on the bug report they've acknowledged here.

Video Sharing on facebook

I want to share image and video on face book wall using sdk.
I use following code to share image
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:#"Classic-Guitar.jpg"];
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
FBSDKShareDialog *shareCodeDialog;
shareCodeDialog = [FBSDKShareDialog new];
[shareCodeDialog setDelegate:self];
[shareCodeDialog setShareContent:content];
[shareCodeDialog setFromViewController:self];
[shareCodeDialog show];
Using this code i am able to post image on wall, but while sending video i am using following code
NSURL *videoURL = [[NSURL URLWithString:#"https://www.youtube.com/watch?v=rSAiSTkVMfs"] absoluteURL];
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
video.videoURL = videoURL;
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
content.video = video;
FBSDKShareDialog *shareCodeDialog;
shareCodeDialog = [FBSDKShareDialog new];
[shareCodeDialog setDelegate:self];
[shareCodeDialog setShareContent:content];
[shareCodeDialog setFromViewController:self];
[shareCodeDialog show];
but it not getting posted gives and error in delegate saying
Error Domain=com.facebook.sdk.share Code=2 "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)" UserInfo=0x16d95990 {com.facebook.sdk:FBSDKErrorArgumentValueKey=https://www.youtube.com/watch?v=rSAiSTkVMfs, com.facebook.sdk:FBSDKErrorArgumentNameKey=videoURL, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Invalid value for videoURL: https://www.youtube.com/watch?v=rSAiSTkVMfs}
The videoURL property has to be an asset URL (one you get from UIImagePickerController) and not a local file URL/web URL (see https://developers.facebook.com/docs/sharing/ios#videos)
If you want to share a YouTube video (or any video available on a website), use FBSDKShareLinkContent instead (see https://developers.facebook.com/docs/sharing/ios#links)

How to Share Link on Facebook using FBSDKShareLink?

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
NSURL *imageURL =
[NSURL URLWithString:#"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];
content.contentDescription=#"This is facebook test";
content.contentTitle=#"Hello";
content.imageURL=imageURL;
FBSDKShareButton *shareButton = [[FBSDKShareButton alloc] init];
shareButton.shareContent = content;
shareButton.center = self.view.center;
[self.view addSubview:shareButton];
I used facebook-ios-sdk-3.24.0.pkg and I am using the above code for link sharing on facebook using fbsdksharekit. This code is working fine but after closing the xcode and reopen that xcode6.0 it shows the below error.
FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h not found.
i import those frameworks i.e FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h to viewcontroller.m file .
can any one tell me what is the problem.Thanks in advance.
Use the Below Code to Share on Facebook, download latest Facebook SDK
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://en.wikipedia.org/wiki/Facebook"];
NSURL *imageURL =
[NSURL URLWithString:#"http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Facebook_Headquarters_Menlo_Park.jpg/2880px-Facebook_Headquarters_Menlo_Park.jpg"];
content.contentDescription=#"This is facebook test";
content.contentTitle=#"Hello";
content.imageURL=imageURL;
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];

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

Resources