我在我的应用程序中处理Facebook共享模块,我想从我的应用程序将图像发布到我的时间轴(墙),但是我想在没有任何对话框的情况下执行此操作,我搜索了大量显示代码的链接没有运气的弃用方法,有人可以帮助我吗?提前谢谢。
public void postImageonWall(String msg ) {
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) {
//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();
// TODO Auto-generated catch block
;
}
答案 0 :(得分:0)
你必须使用Graph Api。 您需要将图像转换为字节数组,然后您可以这样:
String path = "me/feed";
AccessToken at = AccessToken.getCurrentAccessToken();
Bundle parameters = new Bundle();
parameters.putByteArray("picture", bytearray);
HttpMethod method = HttpMethod.POST;
GraphRequest.Callback cb = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
//check graphResponse for success or failure
if(graphResponse.getError()==null){
Toast.makeText(Home.this, "Successfully posted to Facebook", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Home.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();