我可以在 facebook 上成功发布文字,但是当我在 facebook 上发布带有图片的消息时,我无法在 facebook 上发布图片,我也没有收到任何错误,只是得到了
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;
}