Java 使用graph api在Facebook群组上发布照片

Java 使用graph api在Facebook群组上发布照片,java,android,facebook,facebook-graph-api,Java,Android,Facebook,Facebook Graph Api,我正在为一个Facebook群组开发android应用程序。使用graph API,我可以轻松发布文本状态,但当我上传照片时,它返回错误消息 (#100)图片格式不正确 如果我使用相同的代码发布到我的墙上,照片上传效果很好 这是API限制还是有单独的方法将照片上载到组 以下是我的代码: Request photoRequest = Request.newUploadStagingResourceWithImageRequest(session, bitmap, new Request.Callb

我正在为一个Facebook群组开发android应用程序。使用graph API,我可以轻松发布文本状态,但当我上传照片时,它返回错误消息

(#100)图片格式不正确

如果我使用相同的代码发布到我的墙上,照片上传效果很好

这是API限制还是有单独的方法将照片上载到组

以下是我的代码:

Request photoRequest = Request.newUploadStagingResourceWithImageRequest(session, bitmap, new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            if (mProgress != null && mProgress.isShowing())
                mProgress.dismiss();

            if (response.getError() == null) {
                Toast.makeText(NewPostActivity.this, "Successfully shared on the group", Toast.LENGTH_SHORT).show();
                finish();
            } else {
                Toast.makeText(NewPostActivity.this, "Facebook sharing error: " + response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
            }

        }
    });
    Bundle params = photoRequest.getParameters();
    if(message != null) {
        params.putString("message", message);
    }
    if(imageBytes != null) {
        params.putByteArray("picture", imageBytes);
    }
    photoRequest.setParameters(params);
    photoRequest.setHttpMethod(HttpMethod.POST);
    photoRequest.setGraphPath(Constants.URL_FEEDS);
    photoRequest.executeAsync();
编辑
我使用的是Graph API v2.3

似乎可以在一组中发布照片

您可以通过以下路径向photos edge发出POST请求:

/{group_id}/照片

当发布到此边缘时,将创建一张照片

返回类型

Struct {
    id: numeric string,
    post_id: token with structure: Post ID,
    }

似乎对
//feed
POST
请求不允许上传照片(否则它适用于
/me/feed
)。我最终按照建议使用了
//照片
边缘。以下是我的代码-希望它能帮助一些人:

Request photoRequest = Request.newUploadStagingResourceWithImageRequest(session, bitmap, new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            if (mProgress != null && mProgress.isShowing())
                mProgress.dismiss();

            if (response.getError() == null) {
                Toast.makeText(NewPostActivity.this, "Successfully shared on the group", Toast.LENGTH_SHORT).show();
                finish();
            } else {
                Toast.makeText(NewPostActivity.this, "Facebook sharing error: " + response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
            }

        }
    });

    Bundle params = photoRequest.getParameters();
    if(message != null) {
        params.putString("message", message);
        photoRequest.setGraphPath(Constants.URL_FEEDS);
    }
    if(imageBytes != null) {
        params.putByteArray("picture", imageBytes);
        photoRequest.setGraphPath(Constants.URL_PHOTOS);
    }
    photoRequest.setParameters(params);
    photoRequest.setHttpMethod(HttpMethod.POST);
    photoRequest.executeAsync();

谢谢@Ril0n的帮助!