我正尝试使用以下代码将图片上传到Facebook使用Graph API。我不断收到“不良要求”,但不知道为什么。我可以用相同的参数使用curl来上传照片。我用HttpClient使用Java。使用HttpClient将照片上传至Facebook
PostMethod filePost = new PostMethod('https://graph.facebook.com/me/photos');
filePost.setParameter('access_token', 'my-access-token')
filePost.setParameter('message', 'test image')
filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false);
try {
println("Uploading " + file.getName() + " to 'https://graph.facebook.com/me/photos'");
Part[] parts = [new FilePart('source', file.getName(), file)]
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int status = client.executeMethod(filePost);
if (status == HttpStatus.SC_OK) {
println(
"Upload complete, response=" + filePost.getResponseBodyAsString()
);
} else {
println(
"Upload failed, response=" + HttpStatus.getStatusText(status)
);
}
} catch (Exception ex) {
println("ERROR: " + ex.getClass().getName() + " " + ex.getMessage());
ex.printStackTrace();
} finally {
filePost.releaseConnection();
}
UPDATE:More to this。我抓住了一些更多的信息,我得到了这个:
{“error”:{“type”:“OAuthException”,“message”:“一个活跃的访问令牌必须用来查询有关当前的信息用户。“}}
但这看起来不正确,因为我使用Facebook在授权过程后给予我的访问令牌。
工作卷曲代码:
curl -F 'access_token=my-access-token' -F '[email protected]/path/to/image.jpg' -F 'message=Some caption' https://graph.facebook.com/me/photos
您可以将您的工作卷曲代码太Android版本? – 2010-12-17 22:37:20
添加到帖子底部 – Gregg 2010-12-17 22:42:15