如何不同用户在Android中喜欢的帖子

时间:2012-02-17 07:45:28

标签: android facebook facebook-graph-api restfb

我使用restfb编写了facebook android应用程序。

对于不同的帖子,Facebook Graph Api表示将Http删除发送到https://graph.facebook.com/postid/likes 使用访问令牌

示例代码是

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();
    }

执行时我从服务器获取BAD请求400.

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>

解决方案是什么

任何帮助

感谢。

2 个答案:

答案 0 :(得分:2)

要检查的三件事:

  1. 您是否拥有该用户的publish_stream extended permission
  2. 用户是否真的喜欢这个帖子?
  3. 中间是否有代理服务器可能导致HTTP DELETE请求被删除?尝试通过发出GET请求'伪造'DELETE请求,但在你正在发出的请求中添加一个参数&method=delete - Facebook API会将其视为'DELETE',即使它在GET请求中到达< / LI>

    400错误的正文中应该有更好的错误消息 - 如果你提供的话我们可能会帮助更多

答案 1 :(得分:1)

    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();
    }