Android 无法在facebook上发布图片
我可以成功地在facebook上发布文字,但当我在facebook上发布带有图片的消息时,我无法在facebook上发布图片,而且我没有收到任何类型的错误,只是得到了一些信息Android 无法在facebook上发布图片,android,facebook,facebook-graph-api,Android,Facebook,Facebook Graph Api,我可以成功地在facebook上发布文字,但当我在facebook上发布带有图片的消息时,我无法在facebook上发布图片,而且我没有收到任何类型的错误,只是得到了一些信息 json.isNull("id") = null 我使用过类似的许可 private static final String[] PERMISSIONS = new String[] { "publish_stream", "read_stream", "offline_access" }
json.isNull("id") = null
我使用过类似的许可
private static final String[] PERMISSIONS = new String[] { "publish_stream", "read_stream", "offline_access" };
我的代码是
try {
// String response = authenticatedFacebook.request("me");
// JSONObject obj = Util.parseJson(response);
path = Environment.getExternalStorageDirectory().toString() + "/Diegodeals";
Bundle parameters = new Bundle();
parameters.putString("message", txtTitle.getText().toString() + "\n" + txtDesc.getText().toString());
File file = new File(path, "diegodeals.jpg");
System.out.println(file.getAbsolutePath());
Bitmap bitmap = getResizedBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()), 120, 120);
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
if (data != null) {
parameters.putByteArray("picture", data);
}
parameters.putString("access_token", authenticatedFacebook.getAccessToken());
authenticatedFacebook.request("me");
String response = authenticatedFacebook.request("me/feed", parameters, "POST");
JSONObject json;
try {
json = Util.parseJson(response);
if (!json.isNull("id")) {
isWallPostSuccess = false;
return "failed";
} else {
isWallPostSuccess = true;
return "success";
}
} catch (FacebookError e) {
isWallPostSuccess = false;
e.printStackTrace();
}
} catch (Throwable e) {
isWallPostSuccess = false;
e.printStackTrace();
}
return null;
}
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
picture
参数接收图片的URL,而不是图片二进制文件本身。将图片放在一些可公开访问的服务器上并链接到那里,或者使用Facebook的graph API/photos
图片上传机制。在Facebook上上传照片到自己墙上的正确方法是将参数“photo”和“caption”绑定到“me/photos”上。请注意,您的是“图片”和“消息”到“我/提要”,这不起作用
在您的示例中,看起来您有一个要上载的本地图像。这是如何做到的:
Bundle params = new Bundle();
params.putByteArray(
"photo",
Util.getByteArrayFromDrawable(getResources().getDrawable(
R.drawable.picture)));
params.putString("caption", "test message here");
mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener());
否则,为“picture”参数提供URL(而不是字节数组),为“caption”参数提供字符串,并发布到“me/feed”.虽然如果我发布带有图片的文本,则只会成功发布文本,但不会发布图片…您好,Laalto如果我使用92x92尺寸的图像,则会成功发布带有此图片参数的图像。但是Jesse Chen我想将照片发布到facebook,而不是上载照片,这就是我使用我/feed的原因,我已经测试了这个例子,如果我使用了比当时小的图像,图像和标题将被成功发布,但有时不会