I want to allow users without FB app to share open graph - to call share dialog. (With FB app, all working perfect). Is that possible on iOS9? Here is the code (i made content and all):
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
shareDialog.delegate = self;
[shareDialog show];
if (![shareDialog canShow]) {
// update the app UI accordingly
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
// check the error for explanation of invalid content
}
And here what i get when i try to share without FB app (app is not crashing, nothing happen):
-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
Before sharing in the app, user can login successfully in fb with Safari..
Thanks.
Related
I am trying to open Facebook Messenger to send a message from my iOS app. I am currently running FaceBook SDK version 4.37.0. According to iOS - Sharing, this should be possible. It says
People can also share content from your app to Facebook Messenger with Messenger Expression Platform or from Sharing's Message Dialog in iOS SDK.
If you click on the link for Message Dialog, it provides you with the following example:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:myFacebookURL];
content.quote = #"My message";
[FBSDKMessageDialog showWithContent:content delegate:self];
I have implemented this as well as the FBSDKSharingDelegate delegate methods of:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"complete");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"Sharer Error");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"Cancelled");
}
The delegate methods never get called. What I would expect is that a Facebook Messenger dialog would open allowing me to select a friend to message. But nothing opens. And there are no errors being logged.
I do know that facebook is receiving something because I get the following:
FBSDKLog: param {
"advertiser_id" = "xxxxxxxxx";
"advertiser_tracking_enabled" = 1;
"anon_id" = "xxxxxxxx";
"application_
tracking_enabled" = 1;
"custom_events" = "[{\"_eventName\":\"fb_mobile_content_view\",\"_logTime\":1541721304,\"fb_description\":\"MY FEATURE Sent\",\"_ui\":\"no_ui\"},{\"_ui\":\"no_ui\",\"_eventName\":\"fb_messenger_dialog_share_show\",\"_logTime\":1541721310,\"_implicitlyLogged\":\"1\",\"fb_dialog_share_content_type\":\"Status\"}]";
event = "CUSTOM_APP_EVENTS";
extinfo = "[\"i2\",\"com.myApp\",\"1\",\"8.3.6\",\"12.0.1\",\"iPhone10,6\",\"en_US\",\"CST\",\"AT&T\",375,812,\"3.00\",6,60,8,\"America\\/Chicago\"]";
"url_schemes" = "[\"myappID\",\"myscheme1\",\"myscheme2\",\"myscheme3\"]";
}
Any help or pointers would be appreciated.
FBSDKMessageDialog.show(with: FBSDKShareLinkContent(), delegate: nil)
I have the same issue but experimentally I only pass FBSDKShareLinkContent() as a content param and messenger app start
You should also add fb-messenger-share-api key in Info.plist under LSApplicationQueriesSchemes
I am using latest version of facebook sdk in my ios app. I want to share an image on facebook with some initial text.I add my facebook account as a developer in my app on facebook developer account. Currently image is sharing only my account not any other account. Someone tell me please how can i share image by login any facebook account.
Thanks,
For publish any content from another account other than your developer account, you have to submit your application to Facebook Review Process.
If Facebook find your request to use publish action appropriate then they grant this feature for public use. Now, at time of login , If user give permission for publish_action then he/she will be able to post content in respective Facebook Account.
Here I posting code for Login with publish_action permission.
-(void)loginWithPublishActionPermission{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
[SVProgressHUD dismiss];
if (error) {
[[[UIAlertView alloc] initWithTitle:kApp_Name message:error.localizedDescription delegate:nil cancelButtonTitle:kAlert_Ok_Button otherButtonTitles:nil, nil] show];
} else if (result.isCancelled) {
//User Canceled Login
[[[UIAlertView alloc] initWithTitle:kApp_Name message:kAlert_FaceBook_Cancel_Message delegate:nil cancelButtonTitle:kAlert_Ok_Button otherButtonTitles:nil, nil] show];
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:#"publish_actions"]) {
NSLog(#"Result : %#",result);
}
[self performSegueWithIdentifier:kPush_To_Detail_Segue sender:nil];
}
}];
}
To submit your application to Facebook for permission review.
Go to Dashboard of your application in Facebook developer portal.
Then follow below steps for app submission :
1) Dashboard --> Status&Review --> Item in Review --> Start a new submission
2) Select publish_action checkmark --> Add Item
3) Upload your simulator build , Screenshots of application which shows use of publish action feature.
4) Add Step by step instruction to check your flow of application.(How you are using publish_action in your app ?)
5) Submit your app.
In develepors.facebook.com select your app, in that there is an option of "Status & review". In that turn on the switch which says "Do you want to make this app and all its live features available to the general public?"
This will allow other users also to login into your app with their facebook account
check below link
http://i.stack.imgur.com/CW1mu.png
-(void)FbShare
{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://developers.facebook.com"];
content.contentTitle=#“Initial Text”;
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
FBSDKSharePhotoContent *content1 = [[FBSDKSharePhotoContent alloc] init];
UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:#"bleu-heart#3x.png"]];
photo.image = image;
photo.userGenerated = YES;
content1.photos = #[photo];
[FBSDKShareDialog showFromViewController:self
withContent:content1
delegate:nil];
}
What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device.
And this one is when the Facebook app is not installed on the device
And this is my code:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:#"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"icon_circle"]];
[controller setInitialText:#"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
So If you want to share everything, better use FB SDK.
So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.
Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:
If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.
If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.
For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup
I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}
I am trying to send app invitation to facebook friends but getting the following error
app invite error:Error Domain=com.facebook.sdk.core Code=9 "The operation couldn’t be completed. (com.facebook.sdk.core error 9.)"
below is my code
-(IBAction)buttonTapped:(id)sender {
FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://fb.me/115385318808986"];
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
}
#pragma mark - FBSDKAppInviteDialogDelegate
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
// Intentionally no-op.
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"app invite error:%#", error);
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?:
#"There was a problem sending the invite, please try again later.";
NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: #"Oops!";
[[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
and when I am trying to print the error.userInfo it shows a blank dictionary. Please guide.
For facebook sdk 4.0 and later
at first create an applink.
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://www.google.com/myapplink"];
//optionally set previewImageURL
content.appInvitePreviewImageURL = [NSURL URLWithString:#"https://www.google.com/my_invite_image.jpg"];
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content
delegate:self];
see this link https://developers.facebook.com/docs/app-invites/ios
EDIT:
when you create an app link and you have to provide an url scheme,this url scheme added in your project info plist.after that you add a face book canvas platform in face book developer setting page,and provide a canvas url and save it.
If you've been looking everywhere like me to figure out why it's not working, turns out Facebook is deprecating App Invites and will completely stop working as of 2/6/2018:
https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/
I had this error as well. What fixed it was adding
[FBSDKAppEvents activateApp];
in applicationDidBecomeActive:(UIApplication *)application
within the appDelegate. See also https://developers.facebook.com/docs/app-events/ios#appActivation
I am trying to set up Facebook sharing with FBSDK in my iOS app.
I have been reading the documentation here, and currently have
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
working with a content object - FBSDKShareLinkContent.
However, upon trying to use the similar method as specified for Facebook Messenger sharing,
[FBSDKMessageDialog showWithContent:content delegate:self];
i am getting a crash. I caught the error and logged it in one of the delegate methods, and it states "The operation couldn’t be completed. (com.facebook.sdk.share error 202.)
"
I have searched for this specific error but have not found anything directly with the same error. Here is full code
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:kAPPShareLink];
content.contentDescription = kAPPShareDescription;
content.contentTitle = kAPPShareTitle;
if (buttonIndex == 0) {
// Facebook
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
} else if (buttonIndex == 1) {
// Facebook Messenger
[FBSDKMessageDialog showWithContent:content delegate:self];
}
Forgive me if i am missing something obvious, but as this documentation reads, i assume the FBSDKMessageDialog showWithContent: method would work the same way as FBSDKShareDialog showFromViewController: which is working for me.
I am using the latest version of XCode with iOS8.
I had to login and then Post , that is how it worked :
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:#[#"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"https://developers.facebook.com/"];
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
messageDialog.delegate = self;
[messageDialog setShareContent:content];
if ([messageDialog canShow])
{
[messageDialog show];
}
else
{
// Messenger isn't installed. Redirect the person to the App Store.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/en/app/facebook-messenger/id454638411?mt=8"]];
}
}
}];
and the Share Delegate :
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"didCompleteWithResults");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError ::: %#" , error);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"sharerDidCancel");
}
Edit:
[messageDialog canShow] returns NO on the iPad, works fine on iPhone
Posted the issue on Facebook Developers forum.
I was stuck with this for a while and in the end realised that I had not added fb-messenger-share-api under LSApplicationQueriesSchemes in the info.plist file. Just putting this here in case it helps someone. Thanks :)
N.B. It is fb-messenger-share-api and not fb-messenger-api.
Note: This fits more as a comment, but I don't have enough reputation yet to post comments
I get the same error, both Facebook and messenger are updated.
I checked my permissions with
[[FBSDKAccessToken currentAccessToken] permissions]
and I think I have enough:
"contact_email",
"publish_stream",
"user_likes",
"publish_checkins",
"video_upload",
"create_note",
"basic_info",
"publish_actions",
"public_profile",
"photo_upload",
"status_update",
email,
"user_friends",
"share_item"
I tried the same way as OP, and also I tried that:
FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init];
[messageDialog setShareContent:content];
messageDialog.delegate = self;
if ([messageDialog canShow]) {
[messageDialog show];
}
[messageDialog canShow] returns NO, and the delegate methods catch the fail with the 202 error described by the OP.
I tried using the FBSDKSendButton, and doesn't seem to work either.
On the other hand, FBSDKShareDialog works perfectly...
I hope this helps to solve the issue.
This bubbled up again in an interweb search. Nowadays, there is a simple answer for the error Message dialog is not available with code 202:
Facebook's documentation:
Note: Currently the message dialog is not supported on iPads.