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.
Three things to check:
- Do you have the
publish_stream
extended permission for that user? - Does the user actually like the post already?
- 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
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