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/
Related
I was using ios friend request dialog from facebook to send invitation to user for my app. After facebook announced closing of their API it stopped working, Does anyone have an idea how to invite people for application for ios.
You can use this code.
- (void)inviteFriendsOfFacebook
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[mArrTempSelected componentsJoinedByString:#","], #"suggestions", nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:textView.text
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
}
else
{
[Helper showAlertForMessage:#"Invitation Sent Successfully." title:nil cancelButton:#"Ok" otherButton:nil andDelegate:nil withTag:0];
}
}}];
}
Facebook has announced that this will work only for Games application, though one can do this. Just set canvas url for app on Facebook app and use faecbook request dialog. This is very usefull feature for any app.Facebook is working on this feature to make available easily.
We built an IOS game and now it's in the testing process. When we tried to test the Invite Friends via Facebook in game, we found that our request only showed up in two places: 1. The Home Reminders section in the upper right hand corner of the main news feed home on the desktop web version of Faceook.com. 2. The notification jewel on the desktop web version of Faceook.com.
The inviting request NEVER appeared in the notification jewel on device( iPhone or iPad). Does anybody know what we should do? Please help us. Thank you.
Here are the codes:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// Optional parameter for sending request directly to user
// with UID. If not specified, the MFS will be invoked
[NSString stringWithCString:s.c_str() encoding:NSASCIIStringEncoding], #"to",
// Give the action object request information
//#"send", #"action_type",
#"111111111111", #"app_id",
//#"2222222222222", _#"objectid",
nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil message:[NSString stringWithCString:words.c_str() encoding:NSUTF8StringEncoding] title:nil parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if(error)
{
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
}
else
{
if(result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
NSLog(#"User canceled request.");
}
else
{
// Handle the send request callback
if([[resultURL query] rangeOfString:#"request"].length == 0)
{
// User clicked the Cancel button
NSLog(#"User canceled request.");
}
else
{
// User clicked the Send button
//NSString *requestID = [urlParams valueForKey:#"request"];
//NSLog(#"Request ID: %#", requestID);
NSLog(#"User send request.");
}
}
}
}
];
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.
I'm trying to send a comment using Facebook iOS SDK to my FB friends.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[_usersFB valueForKey:#"selectValue"] componentsJoinedByString:#","], #"to",
nil];
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Test Comment"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
}
}
}];
I'm using FB SDK v3.5.3.
I see all the friends in the FBDialog but when I tap on the send button the callback returns no error assuming it worked but my selected friends hasn't received anything.
FYI - My FB app is not in sandbox mode.
Any pointers would be greatly appreciated.
Cheers
Make sure you open the facebook page or app in an iPhone device when you check if it worked.
The notifications will not appear on facebook on on desktop browsers, only on iPhones.
I hope it helps.
I've implemented the basic function to send a invitation request to players' friends to play my game app on iOS devices.
I've followed the instructions here: https://developers.facebook.com/docs/ios/ios-sdk-games/requests/
Everything works fine, I can send requests and friends receive notifications. The problem is that I cannot get the request dialog to appear the way is shown in the above link, in particularly I cannot get the request's preview in the dialog. Does this depend on SDK version? I am currently running with version SDK 3.5.3. Or the problem is somewhere else? any help is greatly appreciated. Thanks
Here's the code that calls the function:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil message:[NSString stringWithFormat:#"Come and play CSR with me!"]
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}];