开发者

Why am I getting a "Method Not Implemented" error when attempting to delete a Facebook test user

开发者 https://www.devze.com 2023-02-09 19:56 出处:网络
I\'m using the Java DefaultHttpClient provi开发者_StackOverflow社区ded by Apache to issue a delete of a test user that we\'ve registered via the /app_id/accounts/test-users endpoint described here htt

I'm using the Java DefaultHttpClient provi开发者_StackOverflow社区ded by Apache to issue a delete of a test user that we've registered via the /app_id/accounts/test-users endpoint described here http://developers.facebook.com/docs/test_users/

the response that is returned is the following HTML:

<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P>
</BODY></HTML>

Using the DefaultHttpClient to POST and GET to the test users api is working fine, it's just sending the DELETE that is the problem. Meanwhile I can also achieve the DELETE (for the same users and access tokens) using a Python script, via curl and using the Firefox REST Client extension.

Does anyone have any idea what the error implies or whether there are any known issues/gotchas when using DefaultHttpClient with the Facebook Graph API?

Update: I've tried analysing the differing requests using tcpdump as suggested by Peter in the comments: sudo tcpdump -i eth2

But all I see are packets going back and forth between me and Facebook, it seems this is a bit of a low level approach to diagnosing the issue.


It seems that Facebook don't want to accept DELETE requests with content and for whatever reason, the DefaultHttpClient (and HttpUrlConnection, I tried that too) either don't set the content length header or set it with a positive value. The fix I discovered is to set the content length header manually to zero. For example:

HttpDelete deleteMethod = new HttpDelete(url);
deleteMethod.setHeader("Content-Length", "0");


HttpResponse httpResponse = client.execute(deleteMethod);
String responseContent = EntityUtils.toString(httpResponse.getEntity(),"UTF-8");
0

精彩评论

暂无评论...
验证码 换一张
取 消