我正在编写用于将图像上传到脸谱相册“个人资料图片”的代码,在从图库中选择图像后,它将转换为字节数组imageBytes
并发送到AsyncTask。我使用fallowing代码上传图像。 facebookProfileImagesAlbumId
拥有专辑“个人资料图片”的ID
Bundle params_ = new Bundle();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
params_.putString("source", encodedImage);
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+facebookProfileImagesAlbumId+"/photos",
params_,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("Login", response.toString());
}
}).executeAndWait();
但它不起作用,Log.i("Login", response.toString());
给出以下消息
{Response:responseCode:200,graphObject:null,error:{HttpStatus:-1,errorCode:-1,errorType:null,errorMessage:无法构造请求体}}
我正在使用Facebook Graph API 2.4
答案 0 :(得分:1)
我使用以下代码将图片发布到Facebook墙或特定相册。
public void PostImage(Bitmap bitmap) {
AccessToken token = AccessToken.getCurrentAccessToken();
if (token != null) {
Bundle parameters = new Bundle(2);
parameters.putParcelable("source", bitmap);
parameters.putString("message", "description");
new GraphRequest(token, "/"+facebookProfileImagesAlbumId+"/photos", parameters, HttpMethod.POST, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("Image Post", "Res =" + response.toString());
}
}).executeAsync();
}
}
希望这有帮助!