Facebook sdk,将图像从Android上传到组页面

时间:2014-11-24 15:14:41

标签: android facebook image facebook-graph-api

只有当我尝试将图像从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");

0 个答案:

没有答案