只有当我尝试将图像从http链接发布到Facebook上的私人组时,代码才能正常工作。
相反,当我尝试将图像上传到私人组时,我在Response
:
{HttpStatus: 400, errorCode: 100, errorType: GraphMethodException, errorMessage: Unsupported method, photos.upload}
这是代码,response
不是 null 但graphObj
null :
Session session = Session.getActiveSession();
if (session != null){
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("message", "test");
Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.gplay_logo);
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
GraphObject graphObj = response.getGraphObject();
if (graphObj!=null) {
JSONObject graphResponse = graphObj.getInnerJSONObject();
//...
}
}
};
Request request = new Request(session, "/" + getResources().getString(R.string.facebook_group_id) + "/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
我在所有许可附近选择了:
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions", "manage_pages", "publish_stream", "photo_upload", "user_photos");