I am fairly new to this field. Can any please help in sharing the in app screenshot to facebook. I have been trying to share screenshot using the [FBDialogs presentShareDialogWithParams] but then it says only FBLinkShareParams: only \"http\" or \"https\" schemes are supported for link thumbnails.
How can we share a in app screenshot of ios device on facebook ?
Hope this helps
-(void)FBshareScreenshot{
if ([FBDialogs canPresentShareDialogWithPhotos]) {
FBPhotoParams *params = [[FBPhotoParams alloc] init];
UIImage *screenshot = [self captureScreenshot]; //calling to capture screenshot
params.photos = #[screenshot];
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error publishing story = %#.", error);
NSLog(#"result = %#.", results);
} else if (results[#"completionGesture"] && [results[#"completionGesture"] isEqualToString:#"cancel"]) {
NSLog(#"User canceled photo publishing.");
} else {
NSLog(#"photo posted");
}
}];
}else {
//The user doesn't have the Facebook for iOS app installed, so we can't present the Share Dialog
/*Fallback: You have two options
1. Share the photo as a Custom Story using a "share a photo" Open Graph action, and publish it using API calls.
See our Custom Stories tutorial: https://developers.facebook.com/docs/ios/open-graph
2. Upload the photo making a requestForUploadPhoto
See the reference: https://developers.facebook.com/docs/reference/ios/current/class/FBRequest/#requestForUploadPhoto:
*/
}
}
-(UIImage *)captureScreenshot{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *imageView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// UIImageWriteToSavedPhotosAlbum(imageView, nil, nil, nil);
return imageView;
}
Related
I am trying to share a link using the FB messenger. When i try to share the link to facebook i keep getting an error. I googled for an answer and the couple of solutions i found did not help since everything in the plist is correct. If anyone has any advice i would really appreciate it, been trying to solve this all day.
Error:
Invalid use of FBAppCall, fb839771929379526 is not registered as a URL Scheme. Did you set 'FacebookUrlSchemeSuffix' in your plist?
Code:
// Check if the Facebook app is installed and we can present
// the message dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:filePath];
params.name = #"My Video";
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentMessageDialogWithParams:params]) {
// Enable button or other UI to initiate launch of the Message Dialog
// Present message dialog
[FBDialogs presentMessageDialogWithLink:[NSURL URLWithString:#"https://developers.facebook.com/ios"] handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog([NSString stringWithFormat:#"Error messaging link: %#", error.description
]);
} else {
// Success
NSLog(#"result %#", results);
}
}];
} else {
// Disable button or other UI for Message Dialog
}
}
When I try to share on Facebook using presentOSIntegratedShareDialogModallyFrom, I can not see the app name. I use the following code:
[FBSettings setDefaultDisplayName:[[FBSettings defaultDisplayName] precomposedStringWithCanonicalMapping]];
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:[arrDetailsOfTour valueForKey:#"WebAddress"]];
params.picture = [NSURL URLWithString:[arrDetailsOfTour objectForKey:#"ImageUrl"]];
params.name = [NSString stringWithFormat:#"%#",[arrDetailsOfTour valueForKey:#"CompanyName"]];
[FBDialogs presentOSIntegratedShareDialogModallyFrom:self initialText:[NSString stringWithFormat:#"%#",[arrDetailsOfTour valueForKey:#"CompanyName"]] image:toursImageView.image url:[NSURL URLWithString:[arrDetailsOfTour valueForKey:#"WebAddress"]] handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
but I am not able to see the app name in the post. I have put Facebook Display name in plist, but still it does not show. Please help.
Apple controls the UI for the iOS integrated dialog, and they don't show the app name. The native Facebook Share Dialogs and the web dialogs will.
I'm using following code to share a picture to Facebook using ShareDialog. However I'm unable to set a caption to this. params does not have a property for a caption.
FBPhotoParams *params = [[FBPhotoParams alloc] init];
params.photos = #[image]; // this is an UIImage instance.
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
NSLog(#"Error: %#",
error.description);
} else {
NSLog(#"Success!");
}
}];
However there's a different method to share a status update with a picture, but this methods allows to share an image as a web link.
presentMessageDialogWithLink:name:caption:description:picture:clientState:handler:
I want to share a local UIImage just like in my first approach, with a caption. Is this possible?
There's no support for captions via the photo share dialog. The user must type in the caption/message themselves.
I am trying to post Facebook page link from my iPhone app on Facebook but it gave me error
Error publishing story :The operation couldn’t be completed.
(com.facebook.Facebook.platform error 102.)
I am using below code:
- (void)showShareFbDialog
{
// Check if the Facebook app is installed and we can present the share dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:#"https://www.facebook.com/hellothemes"];
params.name = #"Title";
params.caption = #"Caption";
params.picture = [NSURL URLWithString:imageName];
params.linkDescription = #"Description";
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
// Present the share dialog
[FBDialogs presentShareDialogWithLink:params.link
name:params.name
caption:params.caption
description:params.linkDescription
picture:params.picture
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
//NSLog([NSString stringWithFormat:#"Error publishing story: %#", error.description]);
NSLog(#"Error publishing story :%#", error.localizedDescription);
} else {
// actions to perform
}
}];
} else {
// Present the feed dialog
[self shareLinkWithAPICalls];
}
}
I am using latest Facebook SDK. Kindly help me to fix the issue.
What i was trying to do was to publish a camera generated photo into facebook with an open graph action.
here is the code i used:
UIImage *imageToShare = [EXPOINNOVAImageCombiner mergeImages:photo TopImage:tbot];
//Custom UIImage to be shared on facebook
NSArray* images = #[#{#"url": imageToShare, #"user_generated" : #"true" }];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"http://emaginelab.com/FBAction/fbtbot.html" forKey:#"tbot"];
[action setObject:images forKey:#"image"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"expoinnovaapp:took_a_photo_with"
previewPropertyName:#"tbot"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
When i set the user_generated flag to false, the post works, but if its true facebook tries to post it, but falls back to the app before the upload finishes.
I already registered my app in facebook, and added the user generated photos capability so, in theory, the app should post a larger version of the photo in the user timeline.
btw the image is 640x640
what am i doing wrong here?
thanks in advance