fail to publish a facebook like from my android app to a given postId

天涯浪子 提交于 2019-11-30 23:38:58

Original post here.

Try to use this library:

dependencies {
    compile 'com.shamanland:facebook-like-button:0.1.8'
}

The simplest way to add like button:

<com.shamanland.facebook.likebutton.FacebookLikeButton
    style="@style/Widget.FacebookLikeButton"
    app:pageUrl="http://url.to.like/page.html"
    app:pageTitle="Title of page"
    app:pageText="Short description of page"
    app:pagePictureUrl="http://url.to.like/picture.jpg"
    />

This view will be drawn in your layout:

After clicking on it you will see the dialog with official Facebook 'Like' plugin.

Read more details.

Using the newest Graph API:

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

    @Override
    public void onCompleted(Response response){
    //Request complete
    }
};
request.executeAsync();

This will have the user like the post with post_id. To unlike, just change the HttpMethod to HttpMethod.DELETE.

First you need to get an access token for the user. Try reading this,

https://developers.facebook.com/docs/facebook-login/access-tokens/

The you can append the access token to your request url or whatever method you choose.

In case you want to go through the entire login flow, check this example :

https://developers.facebook.com/docs/reference/php/facebook-api/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!