Post photo to Facebook group using graph api

I am working on android app for Facebook group. Using the graphics API, I can easily post the status of the text, but when I upload a photo, it returns an error saying

(#100) The picture is not properly formatted

If I use the same code to post to the wall, uploading photos works fine.

Is this an API limitation or is there a separate approach for uploading a photo to a group?

Below is my code:

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();

      

EDIT I am using Graph API v2.3

+3


source to share


2 answers


It seems that the request POST

for /<group-id>/feed

does not allow the upload of a photo (which otherwise works for /me/feed

). I finally got this working with the edge /<group-id>/photos

as suggested. The following code of mine - hoping it helps some:



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();

      

0


source


It seems possible to place a photo in a group.

You can make a POST request to the edge of photos in the following ways:

/ {group_id} / photos

When sent to this edge, a photo will be created.



Ref Return Type

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

      

0


source







All Articles