1

我正在阅读Facebook游戏教程,并在第 5 部分 - 发布 Open Graph Story。这部分侧重于将分数发布到用户分数提要。我遇到的问题是它执行代码,似乎没有任何问题,但没有在 Facebook 上发布分数。这是应该发布他们的分数的代码:

public void postScore(int score){
    Log.d(TAG, "postScore");
    Session session = Session.getActiveSession();

    if (session == null || !session.isOpened()) {
        Log.d(TAG, "SESSION == NULL OR IS NOT OPENED");
        return;
    }

    List<String> permissions = session.getPermissions();
    if (!permissions.containsAll(PERMISSIONS)) {
        Log.d(TAG, "requestPublishPermissions");
        requestPublishPermissions(session);

    }

    Bundle fbParams = new Bundle();
    fbParams.putString("score", "" + score);
    Request postScoreRequest = new Request(Session.getActiveSession(),
        "me/scores",
        fbParams,
        HttpMethod.POST,
        new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                    Log.d(TAG, "error posting");
                    handleError(error, false);
                }
                Log.d(TAG, "successfully posted");
            }
        });
    Request.executeBatchAsync(postScoreRequest);
}// end of postScore() method

其中 PERMISSIONS 定义为:

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

requestPublishPermissions() 定义为:

protected void requestPublishPermissions(Session session) {
    if (session != null) {
        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS)
                // demonstrate how to set an audience for the publish permissions,
                // if none are set, this defaults to FRIENDS
                .setDefaultAudience(SessionDefaultAudience.FRIENDS)
                .setRequestCode(REAUTH_ACTIVITY_CODE);
        session.requestNewPublishPermissions(newPermissionsRequest);
    }
}//end of requestPublishPermissions() method

任何帮助、建议或建议将不胜感激!谢谢!

4

1 回答 1

0

Facebook 控制哪些作为故事进入,哪些不是。当您反复发布高分时,Facebook 不太可能将每个故事都发布到您的时间线上。如果您想要这种行为,我建议将发布直接作为自定义消息实现到时间线,而不是依赖分数 API 为您推送它们。

于 2014-08-09T14:00:48.543 回答