![](/img/trans.png)
[英]Facebook Android SDK - can read profile, but not publish photo to wall
[英]Publish photo on wall with facebook sdk
我正在尝试使用Facebook SDK 3.0 for Android在我的墙上发布照片。 这是代码:
GraphObject graphObject = GraphObject.Factory.create();
Bitmap bmp = BitmapFactory.decodeFile(loadFinalImageSavedFullPath());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
graphObject.setProperty("source", Base64.encodeToString(byteArray, Base64.DEFAULT);
graphObject.setProperty("message", "sup");
com.facebook.Request.executePostRequestAsync(fSession, "me/photos", graphObject, new Callback() {...}
但我总是收到此错误:
I / facebook(10707):{响应:responseCode:400,graphObject:null,错误:{HttpStatus:400,errorCode:324,errorType:OAuthException,errorMessage:(#324)需要上传文件},isFromCache:false}
我尝试过没有Facebook API的POST:
@Override
protected Boolean doInBackground(String... params) {
Bitmap bmp = BitmapFactory.decodeFile(loadFinalImageSavedFullPath());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
List<NameValuePair> pm = new ArrayList<NameValuePair>();
pm.add(new BasicNameValuePair("access_token", params[0]));
pm.add(new BasicNameValuePair("message","sup"));
pm.add(new BasicNameValuePair("source", Base64.encodeToString(byteArray, Base64.DEFAULT)));
String res = postJSONString(https://graph.facebook.com/me/photos, pm);
Log.i(TAG, res);
if (res == null || res.contains("error")) {
return false;
}
return true;
}
同样的问题...
I / facebook(2977):{“错误”:{“消息”:“(#324)需要上传文件”,“类型”:“ OAuthException”,“代码”:324}}
看来这是我管理它的唯一方法:
com.facebook.Request.executeUploadPhotoRequestAsync(fSession, bmp, new Callback() {
缺点,无法在POST中添加评论...
会是什么呢?
谢谢你的时间。
终于让它工作了!!!
com.facebook.Request request = com.facebook.Request.newUploadPhotoRequest(Session.getActiveSession(), bmp, new Request.Callback() {...});
Bundle params = request.getParameters();
params.putString("name", "sup");
request.setParameters(params);
Request.executeBatchAsync(request);
希望它也对您有帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.