2
votes

I want to use Facebook SDK on Android to send Like statuses using Open Graph API. Described here: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
From SDK I got access_token (with publish_actions permission) using SSO. I already registred my app on Facebook Dev Account so I have my app_id.
Now I want to use Open Graph API to send Like status on my wall. So I call https://graph.facebook.com/MY_USER_ID/og.likes with access_token, app_id and object header (using setRequestProperty()) with HttpURLConnection and setRequestMethod to POST.

HttpURLConnection conn;
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("object", "someURL");
conn.setRequestProperty("app_id", "myID");
conn.setRequestProperty("access_token", "myToken");
conn.setRequestProperty("Content-Length", "" + postMessageInBytes.length);

I always get response 400 Bad Request

  {"error":{"message":"An access token is required to request this resource.","type":"OAuthException","code":104}} 

When I'm using Graph API Explorer (developers.facebook.com/tools/explorer/) everything works fine and there is no problem with access token.
When I debug my access token everything looks fine (translated from another language):

ID app: my app ID/name
ID user: user which I used to login
Issued: 1348929549 (yesterday)
Valid until: 1354113549 (in about 2 months)
Valid:  True
Origin: Mobile Web Faceweb
Permission: publish_actions user_status

So the question is, where is the problem with access token?
Thanks for help!

1
Debug your access token using developers.facebook.com/tools/debugCBroe
I edited my question and everything looks fine.Warlock

1 Answers

2
votes

I don't know where exactly was problem, but I started to use AsyncFacebookRunner which is part of Facebook SDK and everything now works fine. As I can see from source code of AsyncFacebookRunner same things are done little bit different.

EDIT: Simple request for Like action

Bundle msgParams = new Bundle();
msgParams.putString("object", mUrl);
Request request = new Request(Session.getActiveSession(), "me/og.likes", msgParams, HttpMethod.POST,
                likeCallback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();