Facebook 3.0如何发布墙?

时间:2013-07-18 13:49:18

标签: android facebook facebook-android-sdk

所以新的facebook 3.0 offers good guides for how to post on wall。但是当它不飞的时候你会怎么做?

我得到了以下来自facebook的回复:

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) Missing message or attachment}, isFromCache:false}

这是我的许可更新:

                Session session = ParseFacebookUtils.getSession();
                if(session != null) {

                    List<String> permissions = session.getPermissions();
                    if (!isSubsetOf(PERMISSIONS, permissions)) {
                        Session.NewPermissionsRequest newPermissionsRequest = new Session
                                .NewPermissionsRequest(this, PERMISSIONS);
                        session.requestNewPublishPermissions(newPermissionsRequest);
                        return;
                    }

                    publishStory();
                }

PERMISSIONS有以下内容:

private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");

这是我的发布代码,非常(不完全)是来自facebook的复制粘贴:

private void publishStory() {
    Bundle postParams = new Bundle();
    postParams.putString("name", "Test");
    postParams.putString("caption", "Another Test");
    postParams.putString("description", mEdit.getText().toString());

    Request.Callback callback = new Request.Callback() {
        public void onCompleted(Response response) {
            JSONObject graphResponse = response
                                       .getGraphObject()
                                       .getInnerJSONObject(); //FIXME <-- here we get the error
            String postId = null;
            try {
                postId = graphResponse.getString("id");
            } catch (JSONException e) {
                Log.i(GlobalValues.LOG_TAG,
                    "JSON error "+ e.getMessage());
            }
            FacebookRequestError error = response.getError();
            if (error != null) {
                Toast.makeText(getActivity()
                     .getApplicationContext(),
                     error.getErrorMessage(),
                     Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity()
                         .getApplicationContext(), 
                         postId,
                         Toast.LENGTH_LONG).show();
            }
        }
    };

    Request request = new Request(ParseFacebookUtils.getSession(), "me/feed", postParams, 
                          HttpMethod.POST, callback);

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}

非常感谢所有帮助。

修改

以下是我在请求时的权限列表:

[status_update, photo_upload, video_upload, create_note, share_item, publish_stream, publish_actions, basic_info]

1 个答案:

答案 0 :(得分:1)

您是否检查过发布权限?您发布的链接中的代码在发送请求之前检查权限。

    // Check for publish permissions    
    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("name", "Test");
postParams.putString("caption", "Another Test");
postParams.putString("description", mEdit.getText().toString());
postParams.putString("message", "My message");