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)
Related
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];
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];
I am using Facebook SDK 4.13 for iOS.
I'm successfully share custom OpenGraph story through [FBSDKShareAPI share]. The problem is - no dialog.
When I'm trying to share the same context through FBSDKShareDialog - dialog appears empty and shared post neither.
Is there a possibilities to share OpenGraph stories through dialog?
I've managed "tune" settings for my OGOStory(OpenGraphObjectStory), so it'll show correctly in fine dialog.
It's a bit confusing that in my app I have models named story and OGOS but, i hope, youl'll manage to understand.
- (void)performShareFacebookWithStory:(STLStory *)story andText:(NSString *)text
{
NSURL *imageURL = [NSURL URLWithString:[story largeImageURL]];
FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImageURL:imageURL userGenerated:NO];
NSDictionary *properties = #{
#"og:type": #"stories_california:story", //OpenGraphObjectStory,
#"og:title": [story title],
#"og:description": [story aboutText],
#"og:url": [self storyUrlForStory:story], // it's NSString
#"og:image": #[photo],
};
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = #"stories_california:story_listen";
[action setObject:object forKey:#"story"];
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"story"; //OpenGraphPreviewPropertyName
[FBSDKShareDialog showFromViewController:_parentVC
withContent:content
delegate:self];
}
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.
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];