Comment contrairement à un poste qu'un utilisateur a aimé facebook dans Android
-
27-10-2019 - |
Question
J'ai écrit facebook Application Android en utilisant restfb .
Pour la différence d'un poste, Facebook Graph Api dit d'envoyer un Http supprimer https: //graph.facebook .com / postID / aime avec le jeton d'accès
Le code échantillon est
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();
}
Lors de l'exécution je reçois BAD demande 400 du serveur.
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>
Quelle est la solution
Toute aide
Merci.
La solution 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();
}
Autres conseils
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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow