我正在一个Android应用程序,并希望从我的应用程序共享一个图像到Facebook但没有显示对话框,我已经尝试如下,但它不工作.Can有人帮我做这个?发布一个图像到facebook失败,在Android使用Facebook SDk 4.0
代码
public void postFb(){ String path = "me/feed";
AccessToken at = AccessToken.getCurrentAccessToken();
Bundle parameters = new Bundle();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Const.bmp_post.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
parameters.putByteArray("picture", byteArray);
HttpMethod method = HttpMethod.POST;
GraphRequest.Callback cb = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
Log.d("=======graph response=======" , graphResponse.toString());
//check graphResponse for success or failure
if(graphResponse.getError()==null){
Toast.makeText(NewPostActivity.this, "Successfully posted to Facebook", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(NewPostActivity.this, "Facebook: There was an error, Please Try Again", Toast.LENGTH_SHORT).show();
}
}
};
GraphRequest request = new GraphRequest(at,path,parameters,method,cb);
request.setParameters(parameters);
request.executeAsync();
}
你得到什么错误? – mdDroid
@mdDroid - 请参阅此错误。“{响应:responseCode:400,graphObject:null,错误:{HttpStatus:400,errorCode:100,errorType:OAuthException,errorMessage:(#100)图片格式不正确}}' –