6

I've spent hours on this and can't get it to work. Basically I just want a button in my app that will 'Like' itself on Facebook. I've created the app on dev Facebook and have an associated App Page. In my code I request these permissions:

_permissions =  [NSArray arrayWithObjects:@"publish_stream", @"publish_actions", @"user_birthday", nil];

I can retrieve a profile picture fine, but when I try to 'Like' using this code:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       _facebook.accessToken, @"access_token",
                                       nil];
        [_facebook requestWithGraphPath:@"329756493773381/og.likes" andParams:params andHttpMethod:@"POST" andDelegate:self];

I get this error response:

(facebookErrDomain error 10000.)" UserInfo=0x20090590 {error={
    code = 200;
    message = "(#200) Requires extended permission: publish_actions";
    type = OAuthException;
}}

When logging in on the app, Facebook asks me for permission to see my birthday, and tell's me it will Post on my behalf but it seems to not get the publish_actions permission.

Is there something i'm missing that I need to do?

I see Temple Run has a Facebook Like button and offers bonus coins for pressing it. This is what I wish to achieve.

EDIT -------

I've changed my permissions to just @"publish_actions", @"user_birthday" and now the auth dialogue says

"This app may post on your behalf, including objects you liked and more"

which seems to be the publish_actions permission, however I was still getting the error

message = "(#200) Requires extended permission: publish_actions";

I've changed this line:

[_facebook requestWithGraphPath:@"329756493773381/og.likes" andParams:params andHttpMethod:@"POST" andDelegate:selrf];

to this:

[_facebook requestWithGraphPath:@"329756493773381/og.likes" andDelegate:self];

and I do now get a response back, although it doesn't post a 'like'

This is the result response:

{
    data =     (
    );
    paging =     {
        next = "https://graph.facebook.com/329756493773381/og.likes?sdk=ios&sdk_version=2&access_token=BAAGeAp3ZBGwoBAPICjlgB5zK0YECyP8yElf8hJoMrx8Qs4vjeZAK5PlXFAVbGM1JyXHE0wZBvU0aBeCzCUTZBejQgoJ44CAIQsrG64TfrHdxjMqWD&format=json&offset=25&limit=25";
    };
}

Any idea what to try next?

EDIT 2 --------------- I'm making progress with this. I've added the users id to the graph request like this

NSString *graphPath = [NSString stringWithFormat:@"%@/og.likes",facebookID];

and used these parameters

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"AAAGeAp3ZBGwoBABvKjsPZAoQQNG9cDPJI2v2TI8acyyPSNtm9ZBkfydHqVZAjSKWSbLuvFwxyxSrCts7kFZCnh7Y6f5PFNlWb6smF8XF33wlRZBgfLyhT1", @"access_token",
                                       @"http://samples.ogp.me/329756493773381", @"object",
                                       nil];

and now I get a like showing up on my timeline :-) I was using the access-token supplied by the Facebook login, but it seems the one supplied by the graph object is different.

Now, the like that i'm seeing has this pattern:

Darren likes object on MyAPP

Is it even possible to have it as

Darren likes MyAPP with it linking to the app Facebook page?

Thanks

Darren
  • 10,182
  • 20
  • 95
  • 162
  • Is the app type set to 'Native/Desktop' in the FB app settings -> advanced -> authentication? – borisdiakur Jul 07 '12 at 13:42
  • Yes it is. I now don't think this is possible. You can like things within your app, like a recipe in a recipe app, but you can't like fan pages etc.. – Darren Jul 07 '12 at 15:05
  • You are right. The [docs](https://developers.facebook.com/docs/opengraph/actions/builtin/likes/) say that the following conditions must be true in order to publish a built-in like action: The in-app content has an Open Graph object page that is properly marked-up using Open Graph metatags and the viewer has intentionally clicked on a custom in-app "like button" **associated with the in-app content**. However you can always redirect to your Facebook page. – borisdiakur Jul 07 '12 at 16:13

2 Answers2

5

Check if you have done the steps below:

https://developers.facebook.com/docs/opengraph/tutorial/

"Note: The user-prompt for this permission will be displayed in the first screen of the Enhanced Auth Dialog and cannot be revoked as part of the authentication flow." - link

Try this if you havent already:

Auth Dialog -> Configure how Facebook refers users to your app - > Add publish_actions permissions.

https://developers.facebook.com/docs/opengraph/authentication/

"To enable the new Auth Dialog, go to the App Dashboard, and enable the Enhanced Auth Dialog setting in the Advanced section of your app." -link

Hope this helps!

AlexanderN
  • 2,610
  • 1
  • 26
  • 42
  • 1
    I've tried resetting the simulator. I've removed the app from my Facebook account settings, this forces it to ask for permission again. It asks me and tells me that it will post on my behalf, yet I still don't get publish_actions permission! – Darren Jul 06 '12 at 10:35
  • Found this elsewhere on SO: "I think fb will change this behaviour in the near future, but currently it seems that the app must be in the category 'game' to request the 'publish_actions' permission... (i am in the sandbox mode)" – AlexanderN Jul 06 '12 at 10:42
  • My app is in the Game category, although I think that referred to when publish_actions was in BETA testing. It has full release now. – Darren Jul 06 '12 at 10:49
  • I've read through it, but as the example sets up a website, it's hard to follow. I'm pretty sure I have it all set up properly. The Auth dialogue has publish_actions as User & Friend permissions and publish_stream as Extended permission. The silly thing is you can't get to this point without entering an app store id in the basic settings under Native iOS APP!!so have to put a dummy one in. I still don't get the permission – Darren Jul 06 '12 at 12:49
  • Oh, and I can't submit the graph until i've used it once which obviously I can't do. – Darren Jul 06 '12 at 12:50
  • I made a bit of progress, please see edit at bottom of original question. – Darren Jul 07 '12 at 09:46
  • More progress, see Edit 2. Thanks – Darren Jul 07 '12 at 13:06
  • @Darren I was just about to suggest the changes you made, but instead sending the page id as the object. However, it seems that its not possible at this time. Facebook did have a huge API change a few days ago so you could try it anyways. http://stackoverflow.com/questions/9809783/like-application-api http://stackoverflow.com/questions/3061054/like-a-page-using-facebook-graph-api – AlexanderN Jul 07 '12 at 13:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13549/discussion-between-alexandernorway-and-darren) – AlexanderN Jul 07 '12 at 13:29
0

This seems to be the same problem I was having on this SO question: Facebook iOS SDK 3.0, implement like action on a url?

But if you want to like you facebook page in the app, there is no way to do that in Objective C. Only with the javascript Like button which you can generate here: https://developers.facebook.com/docs/reference/plugins/like/

The way Temple Run does it is to display the Like button in a web-view, so their like button is actually on their server, this is perhaps an ugly-hack but will work for liking a page.

Community
  • 1
  • 1
Joakim Engstrom
  • 6,243
  • 12
  • 48
  • 67