4

I am working in an android application where I use the facebook android sdk to login to the application.I get the access token from the facebook sdk when user logged in to the application through facebook sdk.

So is it possible to like a page in facebook pragmatically having access token of a user.

Rushabh Patel
  • 3,052
  • 4
  • 26
  • 58
Arun PS
  • 4,610
  • 6
  • 41
  • 56

2 Answers2

19

It's not possible to like a page programmatically, only comments and posts. I don't know why you marked the previous answer as correct, it does not work and it's quite misleading.

hbot
  • 724
  • 8
  • 19
0

To like a post on facebook, I use this part of code to create the request.

Request likeRequest = new Request(Session.getActiveSession(), pageid + "/likes", null, HttpMethod.POST, new Request.Callback() {
    @Override
        public void onCompleted(Response response) {

    }
});

Where I already logged in to Facebook, so I can just call the Session.getActiveSession().

Then I execute the request with:

Request.executeBatchAndWait(likeRequest);

You should run this in an Asynctask, since you are not allowed to do network stuff on your main thread.

harmjanr
  • 930
  • 2
  • 11
  • 27
  • I used these imports: import com.facebook.HttpMethod; import com.facebook.Request; import com.facebook.Response; import com.facebook.Session; Did you add the facebook sdk as a Library project in your Android project properties? – harmjanr Jun 21 '13 at 12:42
  • 2
    not work, response contain: `{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) App does not have permission to make this call}, isFromCache:false}` – ryder Dec 19 '13 at 14:25
  • Please mark this answer as unanswered, because it is not allowed as mentioned bellow. – X-HuMan Jun 19 '14 at 14:51
  • I think I read it wrong, can't really remember it since it's more than a year ago.. Would love to delete my answer, but I can't since it's accepted as answer :( – harmjanr Jul 01 '14 at 07:06
  • https://developers.facebook.com/docs/graph-api/reference/v2.1/object/likes .... this seems relevant to the discussion for anyone else. talking about liking an OBJECT tho. – sirvon Aug 28 '14 at 05:36