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;
}