Facebook share example not working - facebook

I followed the set up for my own application. https://developers.facebook.com/docs/ios/getting-started/
I then used the overview example, found here: https://developers.facebook.com/docs/ios/share-dialog/
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
The share dialog appears, like in the example. I press post and it successfully returns to the app. All looks like its working right? But when I return to the facebook wall and my profile there is no status update. The logs are not displayed so something is going wrong.
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
Any ideas? Facebook redirect you to stackoverflow to get help because they have facebook developers registered.

First, the final part on the first link, about the .plist, is really important. It has to be with the correct info from your app, in order to the share feature to work. Re-check that if you can.
Anyway, the NSLog not printing anything on the console is strange, have you tried searching(command + f) for the message output on the console? Did you try debugging your app and putting breaking points on the 'if' condition to see the state of the error instance?
I don't know if you didn't put it here, or forgot to do it on code, but are you logging the user and checking if the facebook user session is valid? That has to be checked in order for the share to work.
PS: If you are using your facebook App on sandbox mode, any share you do, will only appear on the timeline of the users that are allowed to use the fbApp.

Related

(Facebook SDK 4.x) Sharing a link to a friends wall

I'm currently updating from Facebook SDK 3.x to 4.x on iOS and Android and can't seem to figure out how to share a link to a friends wall. Previously I used FBWebDialogs that accepted a "to" field in the parameters, but now using the FBSDKShareLinkContent and FBSDKShareDialog there doesn't seem to be any option like this.
I couldn't find any explicit mentioning of fully dropping support for this in 4.x, so would anyone know if this is still possible in some way? Preferably with a dialog and not behind the scenes.
Thanks.
This piece of code should do the trick..
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/feed"
parameters: #{ #"message" : #"your messag / link"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Post id:%#", result[#"id"]);
}
}];
}

Custom OpenGraph methods failing when posting

I am getting the following error when attempting to post to OpenGraph using the Share Dialog with the FB iOS SDK v 3.17.0.:
Error : Error Domain=com.facebook.Facebook.platform Code=102 "The operation couldn’t be completed. (com.facebook.Facebook.platform error 102.)" UserInfo=0x176d43a0 {error_code=102, error_description=An error occurred during publishing., app_id=xxxxxxxxxxx, error_reason=The operation couldn’t be completed. (FBAPIErrorDomain error 2500.)}
This error is returned by handler callback of the presentShareDialogWithOpenGraphAction method. When calling this method, the transition to the FB App occurs and the contents of the post are shown in the UI (although, the supplied photo shows briefly and then disappears). I also see an alert dialog in the FB App stating:
Oops, Something Went Wrong. There was a problem posting your status. We've logged the error and will look into it.
After pressing Post in the FB app, my app opens again with the above error message.
The (abbreviated) code for what I am doing is below. Note that my object type is gift, my custom method is send, and both appear to be set up correctly on the developer site. Any help is much appreciated.
id<FBGraphObject> object = [FBGraphObject openGraphObjectForPostWithType:#"myNamespace:gift"]
title:#"Gifter"
image:#"http://imgur.com/gallery/Omhe1V3"
url:#"http://www.myAppsUrl.com"
description:#"A gift for you"];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object forKey:#"gift"];
[action setTags:#[targetFacebookId]]; ///S.O. Note: The Id is obtained elsewhere.
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = #"myNamespace:send";
// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"myNamespace:send"
previewPropertyName:#"gift"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
NSLog(#"Error : %#",error);
}];
}
Look carefully on the parameters you provide. FB doesn't tell you what's wrong but just returns this general error.
I just had the same problem and apparently my namespace was wrong.
So my suggestion - double and triple check all the params you are passing to FB

Facebook posting error in ios

Here i am trying to add a post to facebook using following code.
FBAppCall *appCall = [FBDialogs presentShareDialogWithLink:urlToShare
name:#"Title"
caption:nil
description:#"description"
picture:nil
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
But this isn't working. It give following error.
Error Domain=com.facebook.Facebook.platform Code=102 "The operation couldn’t be completed. (com.facebook.Facebook.platform error 102.)" UserInfo=0x1cde3340 {error_code=102, action_id=E780C3AA-1387-4B9C-9A3A-9A16FB54BC59, error_message=An error occurred during publishing., app_id=558567750859724}
Here i am working on cocos2d, is this can be the reason.
Go to your app's settings under the Facebook developer portal.
Go to open graph > types
Choose the action type using and turn on "User Generated Images" for that action type. Save these settings and try again. It will work.
I encountered this error as well, make sure you disable the sandbox mode in Facebook admin panel before distributing to any other user :P
I recently encountered this error when the link I tried to post did not load correctly (was loading a 404 page). Not sure why, but maybe Facebook requires the link work.. Either way they need to make their error messaging more specific.

Is it possible for user of an ios app to like a URL on facebook using the facebook-sdk?

I am creating an iOS app where I want to allow the user to like a specific URL. I've tried to use the following code (as mentioned on the Facebook developers page) to like a specific url:
**- (IBAction)likeClicked:(UIButton *)sender {
SLAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[FBSession setActiveSession:appDelegate.session];
if (appDelegate.session.isOpen)
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"object"] = #"http://samples.ogp.me/226075010839791";
[FBRequestConnection startForPostWithGraphPath:#"me/og.likes"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"Error %#",error.localizedDescription);
NSLog(#"result %#",result);
// handle the result
}];
}
}**
But the above code only allows me to like the URL if I am authorized as an admin of that app on the facebook developer page.
If I am not an admin to the app with that specific app id , I get an error description as following:
Error The operation couldn’t be completed. (com.facebook.sdk error` 5.)
There are different solutions given on Stack Overflow for this but none of them seem to be working for me. I've checked for permissions and I have added the "publish_actions" permission to permissions list.
Is there another reason why i might be getting this error?
Is there another workaround using which i can like a specific URL on facebook?
There would be couple of places to check
- Is your Facebook app under "sandbox mode", if it is you will have to turn it off once you are sure with your development.
If you have just created a FB graph action:
You are required to submit the action through the FB developer console and it usually takes couple days for them to approve, and once approved other users can start using the "like" action.
Until you get the action approved, only the App developers, testers and admins (on the FB developer site) for this particular app would be able to complete the action and see the results on their FB timeline.

How To make a challenge request in Facebook game

I'm pretty new in using the facebook SDK.
I have kind of a racin app in facebook and I want to challenge other friends. Also friends which have not installed the app.
I read on the facebook developer page
Match Making
Keep in mind that requests can be sent to any player that has already
installed the game;
But to reach more users I want to send challenge request also to any of my users in my friendlist.
Do I have to send those people which haven't installed the app an app request instead?
Does anybody have some experience with match making games in facebook? Maybe a nice tutorial on the web? The FB Doc for me is very superficial.
Thanks in advance
Import FacebookSDK in your application and Use below code.
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just smashed %d friends! Can you beat it?", nScore]
title:#"Smashing!" 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.");
}
}}
friendCache:nil];
}