簡體   English   中英

使用圖形api在Facebook組上發布照片

[英]Post photo on Facebook group using graph api

我正在為一個Facebook群組開發Android應用程序。 使用圖形API,我可以輕松發布文本狀態,但是當我上傳照片時,它會返回錯誤說明

(#100) The picture is not properly formatted

如果我使用相同的代碼發布到我的牆上,照片上傳工作正常。

這是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

似乎可以在一組中發布照片。

您可以從以下路徑向照片邊緣發出POST請求:

/ {GROUP_ID} /照片

發布到此邊緣時,將創建照片。

鏈接返回類型

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

似乎對/<group-id>/feedPOST請求不允許上傳照片(否則適用於/me/feed )。 我終於按照建議使用了/<group-id>/photos edge。 以下是我的代碼 - 希望它有助於一些:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM