gpt4 book ai didi

android - 使用 facebook sdk 在墙上发布照片

转载 作者:太空狗 更新时间:2023-10-29 16:41:18 25 4
gpt4 key购买 nike


我正在尝试使用 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): {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}, 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): {"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":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);

希望对你也有帮助;)

关于android - 使用 facebook sdk 在墙上发布照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17370126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com