How to unlike a post that a user has liked in facebook in android

↘锁芯ラ 提交于 2019-12-23 03:14:14

问题


I have written facebook android application using restfb .

For unlike a post , Facebook Graph Api says to send an Http delete to https://graph.facebook.com/postid/likes with the access token

The sample code is

String postURL = FacebookAppConstants.GRAPH_API_ACCESS+"/"+postID+
            "/likes&access_token="+FacebookAppConstants.accessToken;

    Log.out(logFlag, logTag, "########Delete URL = "+postURL);
    HttpDelete dislikePost = new HttpDelete(postURL);
    Log.out(logFlag,logTag,"####Method : "+dislikePost.getMethod());


    try {
        HttpResponse response = httpClient.execute(dislikePost);

        Log.out(logFlag, logTag,response.getStatusLine().toString());


    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

While executing i am getting BAD Request 400 from the server.

HTTP/1.1 400 Bad Request

    <HTML><HEAD>
D/SMF     ( 2546): <TITLE>400 Bad Request</TITLE>
D/SMF     ( 2546): </HEAD><BODY>
D/SMF     ( 2546): <H1>Method Not Implemented</H1>
D/SMF     ( 2546): Invalid method in request<P>
D/SMF     ( 2546): </BODY></HTML>

What is the solution

Any help

Thanks.


回答1:


Three things to check:

  1. Do you have the publish_stream extended permission for that user?
  2. Does the user actually like the post already?
  3. Is there a proxy server in the middle which could be causing the HTTP DELETE request to be dropped? try 'faking' a DELETE request by making a GET request but adding a parameter, &method=delete to the request you're making - the Facebook API will treat this as a 'DELETE' even if it arrives in a GET request

There should be a better error message coming back in the body of the 400 error - if you provide that we can probably help more




回答2:


    String postURL = FacebookAppConstants.GRAPH_API_ACCESS+"/"+postID+
            "/likes&access_token="+FacebookAppConstants.accessToken;

    Log.out(logFlag, logTag, "########Delete URL = "+postURL);

    HttpGet dislikePost = new HttpGet(postURL+"&method=DELETE");


    try {
        HttpResponse response = httpClient.execute(dislikePost);
        HttpEntity entity = response.getEntity();
        String body = EntityUtils.toString(entity);
        Log.out(logFlag, logTag, "Body : "+body);           

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


来源:https://stackoverflow.com/questions/9324618/how-to-unlike-a-post-that-a-user-has-liked-in-facebook-in-android

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