facebook使用图形api错误发布图像/文本

时间:2014-10-08 12:25:41

标签: android facebook facebook-graph-api

需要发布状态消息,或者如果用户在Facebook上选择了带有该状态消息的图像而不使用对话框。

final Session sessionfb = ParseFacebookUtils.getSession();

    List<String> permissions = sessionfb.getPermissions();
    if (!permissions.contains("publish_actions")) {

        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                FlyTags.this, Arrays.asList("publish_actions"))
                .setCallback(newPermissionsCallback).setRequestCode(1);
           sessionfb.requestNewPublishPermissions(newPermissionsRequest);

    }
    else {

        Bundle parameters = new Bundle();
        parameters.putString("message", mfinalmsg);
        parameters.putString("description", "test");

        if (imgdata != null) {

            parameters.putByteArray("picture", imgdata);
                      }
        new Request(sessionfb, "me/photos/feed", parameters, HttpMethod.POST,
                new Request.Callback() {
                    public void onCompleted(Response response) {

                        Debug.e("facebook post response",
                                response.toString());
                    }
                }).executeAsync();

回复:

{Response:  responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 100, errorType: FacebookApiException, errorMessage: Invalid parameter}, isFromCache:false}

1 个答案:

答案 0 :(得分:0)

如果状态包含文字,请使用我/ Feed 。如果附加图片,请使用我/照片。您应该拥有发布权限。

String graphapimethod = "me/feed";
    Bundle parameters = new Bundle();
    parameters.putString("message", mfinalmsg);
    parameters.putString("description", "testhashmash");

    if (imgdata != null) {

        graphapimethod = "me/photos";
        parameters.putByteArray("picture", imgdata);

    }
    // "me/feed"
    new Request(session, graphapimethod, parameters, HttpMethod.POST,
            new Request.Callback() {
                public void onCompleted(Response response) {
                    /* handle the result */

                    if (response.getError() == null) {
                        Toast.makeText(FlyTags.this, "Posted succeffully.",
                                Toast.LENGTH_SHORT).show();
                        dialog.dismiss();

                    }

                    else {

                        Toast.makeText(FlyTags.this,
                                "oops..please try again",
                                Toast.LENGTH_SHORT).show();
                    }

                    Debug.e("facebook post response", response.toString());
                }
            }).executeAsync();