FBDialogs canPresentMessageDialogWithParams returns false - ios

I'm currently trying to add Facebook SDK to the iOS version of my app. The login, logout, share, and request features are all currently working, but I'm having difficulty getting the MessageDialog feature to work. The Facebook app and the Facebook Messenger app are currently installed on my devices. However, every time I call 'FBDialog canPresentMessageDialogWithParams:params' it returns false.
My guess is that this feature doesn't work while the app is still in development mode, but that is just a guess. Does anyone know if Message Dialog works with apps that are under development? Or do you have any ideas as to what I am doing wrong?
I've also included my code in case I've made any bone-headed mistakes. Any help is greatly appreciated!
// 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/"];
params.name = #"Flash Bear";
params.caption = nil;
params.picture = nil;
params.linkDescription = #"I'm playing Flash Bear. Why don't you come join me?";
// If the Facebook Messenger app is installed and we can present the share dialog
if ([FBDialogs canPresentMessageDialogWithParams:params]) {
// Present message dialog
[FBDialogs presentMessageDialogWithParams:params
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(#"Error messaging link: %#", error.description);
} else {
// Success
NSLog(#"result %#", results);
}
}];
} else {
// Present the feed dialog
// Put together the dialog parameters
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Sorry!"
message:#"There was an error connecting to FB Messenger. Please make sure that it is installed."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
}

I also had same problem with my application.
I resolved it by checking active session state. If state for active session is other than open then we need to open session again.
For doing the same use following code.
if([FBSession activeSession].state != FBSessionStateOpen){
BOOL result = [FBSession openActiveSessionWithAllowLoginUI:NO];
if(result)
{
//Do your stuff here
}
}
Best luck.

Related

Using FB Messenger To share link

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
}
}

Facebook request profile Graph API not working on iOS 7 native facebook non logged in

So I ran into something I can't explain. I've got two devices
Iphone 4
Running iOS 7.0.6. With Native Facebook app installed. But not logged in
iPhone 5s
Running iOS 7.1. With Native Facebook app installed and user logged in.
When I try to access the profile data. It's running smoothly on an iPhone 5s, but breaks after permission dialog on the iPhone 4. So the user allows for sharing specific info to the app. Then at a next screen I'm confronted with a general error message (in Facebook app), saying it was unable to process.
This is how I got it working so far.
Facebook permission
// Make request facebook
[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObjects:#"email", nil]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
{
if (error)
{
NSLog(#"Facebook Errors: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook unable to connect"
message:#"Facebook error message here"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if (FBSession.activeSession.isOpen)
{
// Login via Facebook succeeded.
// We have a session.
[self facebookLoginRequestForMe:onCompletion withScore:score];
}
else
{
// We could not login to Facebook.
if (onCompletion)
{
onCompletion(false);
}
}
}];
Trying to access profile
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser>* fbUser, NSError *fbError)
{
NSString* fbUserEmail = [fbUser objectForKey:#"email"];
bool fbSuccess = (!fbError && fbUserEmail && fbUserEmail.length > 0);
if (fbSuccess)
{
NSString* facebookImageURL = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", fbUser.id];
NSLog(#"User name: %#", fbUser.name);
NSLog(#"User email: %#", fbUserEmail);
NSLog(#"usr_id: %#", fbUser.id);
NSLog(#"usr_first_name: %#", fbUser.first_name);
NSLog(#"usr_middle_name: %#", fbUser.middle_name);
NSLog(#"usr_last_name: %#", fbUser.last_name);
NSLog(#"usr_username: %#", fbUser.username);
NSLog(#"usr_birthday: %#", fbUser.birthday);
NSLog(#"avatar url: %#", facebookImageURL);
}
else if (onCompletion)
{
onCompletion(false);
//TODO: present custom error
}
Am I missing some special callback data I need to present?
Thanks!
Don't believe this! But got it resolved
Scenario: if you have not signed in on Facebook natively (settings -> Facebook -> login credentials here), your device will use the Facebook app to validate the authorization for profile data via Facebook.
This will not work if you have not put the Facebook app in Live mode.
Go to developer.facebook.com
Go to apps
Select Status / review
Do you want to make this app and all its live features available to the general public? YES
You're done!

facebook share fb-event with webdialog (on iOS)

Hi I have the following problem.
If I share an facebook event url (like https://www.facebook.com/events/) from an iOS app I have two possibillities:
(1) iOS facebook app is installed
(2) iOS facebook app is not installed
I case 1 everything works just fine. The facebook app fetches the event information, shows up a right preview and also the post on the facebook wall is right.
In case 2 I use the FBWebDialods class and it shows up a preview without the picutre and also the post on the facebook wall is just text. No image and no attend button.
Has somebody an idea of how I can get the same resulting post on the facebook wall in both cases?
i get the response from https://developers.facebook.com/docs/ios/share/:
// Check if the Facebook app is installed and we can present the share dialog
FBShareDialogParams *params = [[FBShareDialogParams alloc] init];
params.link = [NSURL URLWithString:#"https://developers.facebook.com/docs/ios/share/"];
params.name = #"Sharing Tutorial";
params.caption = #"Build great social apps and get more installs.";
params.picture = [NSURL URLWithString:#"http://i.imgur.com/g3Qc1HN.png"];
params.description = #"Allow your users to share stories on Facebook from your app using the iOS SDK.";
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
// Present the share dialog
} else {
// Present the feed dialog
}
and in Present the share dialog you add :
[FBDialogs presentShareDialogWithLink:params.link
name:params.name
caption:params.caption
description:params.description
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]);
} else {
// Success
NSLog(#"result %#", results);
}
}];
i hope this help you

Detect successful facebook post using FBDialogs

I'm trying to present the facebook share dialog from my iOS app.
This code opens the facebook app and shows the dialog:
FBShareDialogParams* params = [[FBShareDialogParams alloc] init];
params.link = urlToShare;
params.name = #"Test";
params.description = #"Description";
params.picture = [NSURL URLWithString:FB_IMG_URL];
BOOL canPresentShareDialog = [FBDialogs canPresentShareDialogWithParams:params];
if (canPresentShareDialog) {
[FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
if ([FBErrorUtility shouldNotifyUserForError:error]) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Facebook-Error!" message:[FBErrorUtility userMessageForError:error] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
} else {
NSLog(#"SUCCESS");
}
}];
}
In the completion handler I want to know if the user canceled the action. The results dictionary should tell me that. However I only get didComplete=YES in the dictionary but not a completionGesture. The NSError object is always nil.
The results dictionary is explained here: https://developers.facebook.com/ios/share-dialog/
So the problem is I can't tell if the post was successful or not.
Is something wrong with my code?
As stated in the doc, the "completionGesture" field is "only available if the user logged into your app".
So if the user has never used Facebook login with your app before, you will not get that field, and will only see the "didComplete" field.
If I am not wrong then you want to know if user is unable to post the data on facebook because of some error or because he pressed cancel button. If this is the case then use the code given below
[FBDialogs presentShareDialogWithParams:shareParams
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error publishing story.");
} else if (results[#"completionGesture"] && [results[#"completionGesture"] isEqualToString:#"cancel"]) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"Story published.");
}
}];
its been taken from Facebook Developer Reference. Let me know if it helps. Thanks

nil resultURL after successfully posting with FBWebDialogs (Facebook SDK 3.5)

I'm integrating Facebook on my application to share links of websites. I'm using the Feed Dialog to accomplish this and I'm following this tutorial:
https://developers.facebook.com/docs/howtos/feed-dialog-using-ios-sdk/.
I've managed to login and post to Facebook but I wanted to add a message when the post was successful. The tutorial has this built in, but every time I post, I see "User canceled story publishing." in the Log which is the message that is displayed when the user clicks on cancel. Besides I've confirmed with the debugger that the param resultURL received by the handler is always nil even on successful posts.
At first I though it was a configuration issue in my Facebook App, but I decided to make a test. I opened the RPSSample that comes with the framework, added a completion handler to the presentRequestsDialogModallyWithSession call in the clickInviteFriends method in the RPSFriendsViewController.m view controller and I was getting a nil resultURL on successful posts there too.
I'm I missing something?
I know the 3.5 SDK version is very new, but according to the documentation I should be getting a valid resultURL param after posting through a Facebook Web Dialog so I'm not sure if it's a bug or if I'm missing some callback or handler somewhere.
Just in case, this is my call to the Feed Web Dialog. It has minor changes compared to the one that comes in the tutorial (it's actually simpler)
- (void)publish: (EntityToShare *)entityToShare {
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
entityToShare.link, #"link",
nil];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User clicked the Cancel button
NSLog(#"User canceled story publishing.");
} else {
// User clicked the Share button
NSString *msg = [NSString stringWithFormat:
#"Posted story, id: %#",
[urlParams valueForKey:#"post_id"]];
NSLog(#"%#", msg);
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:msg
delegate:nil
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];
}
We have a fix for this in place and will be pushed out soon.
Edited:
This has now been fixed in the SDK release 3.5.1
Check it out here: https://developers.facebook.com/ios/

Resources