Android How to like a post with facebook 3.0 sdk

2019-03-28 10:49发布

问题:

I want to implement "Like" option in my Android app, but I don't know which Request to use.

I have a valid facebook Session opened and the ID post I want to like.

How can I implement this function?

Thanks

回答1:

I found a solution.

To like post I've implemented a simple POST request using likes connection of facebook post id.

This is the code:

Request likeRequest = new Request(Session.getActiveSession(), fBPostId + "/likes", null, HttpMethod.POST, new Request.Callback() {

         @Override
         public void onCompleted(Response response) {
                Log.i(TAG, response.toString());
         }
});
Request.executeBatchAndWait(likeRequest);


回答2:

A cursory search (1, 2, 3) seems to indicate that it's not possible to directly "Like" things as a user via the Graph API, for security/spam reasons. One commonly-suggested alternative has traditionally been to show a Facebook-controlled "Like" button in a WebView and include that in your application instead.

However, more recently, the Facebook developer guide has provided one possible solution for how you can implement "like"-style functionality in your app when it comes to publishing stories on the user's behalf, though it's not precisely the same thing as what you seem to be asking for.