facebook sdk 3.0获得好友分数返回空(android)

时间:2013-12-29 22:07:41

标签: android facebook facebook-graph-api facebook-sdk-3.0

我试图使用facebook的得分api。

所以我发布了这样的分数:

public void postScore(int score) {
    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.e("posting score",
                                "Posting Score to Facebook failed: "
                                        + error.getErrorMessage());
                    } else {
                        Log.i("posting score",
                                "Score posted successfully to Facebook");
                    }
                }
            });
    Request.executeBatchAsync(postScoreRequest);
}

成功!

即时获取用户评分:

public static void getScore() {
    Request postScoreRequest = new Request(Session.getActiveSession(),
            "me/scores", null, HttpMethod.GET, new Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Log.d("getting score",
                                "Getting Score from Facebook failed: "
                                        + error.getErrorMessage());
                        Scores.isMyScoreLoaded = false;
                    } else {
                        Log.d("getting score",
                                "Got Score  successfully from Facebook");
                        Log.d("score object", response.getGraphObject()
                                .getInnerJSONObject().toString());
                        Scores.isMyScoreLoaded = true;

                    }

                }
            });
    Request.executeBatchAsync(postScoreRequest);
}

成功!!!

但是当我试图获得所有朋友的分数时,就像这样:

public static void getFriendsScores() {

    Request postScoreRequest = new Request(Session.getActiveSession(), "/"
            + R.string.app_id + "/scores", null, HttpMethod.GET,
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Log.d("getting all scores",
                                "Getting Scores from Facebook failed: "
                                        + error.getErrorMessage());
                        Scores.isFriendsScoresLoaded = false;
                    } else {
                        Log.d("getting all scores",
                                "Got Scores successfully from Facebook");
                        Log.d("score object", response.getGraphObject()
                                .getInnerJSONObject().toString());
                        Scores.isFriendsScoresLoaded = true;

                    }

                }
            });
    Request.executeBatchAsync(postScoreRequest);
}

* IT工作! (没有错误)但是它回归了一个空的时间:(*

谢谢你的帮助!!!!

亚基尔。

1 个答案:

答案 0 :(得分:0)

你是如此亲密

您不需要第一个正斜杠,而是传递resourceID而不是实际的App IP。所以更新的代码看起来像这样..

public static void getFriendsScores() {

    Request postScoreRequest = new Request(Session.getActiveSession(), 
            getResources().getString(R.string.app_id) +"/scores", null, HttpMethod.GET,
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Log.d("getting all scores",
                                "Getting Scores from Facebook failed: "
                                        + error.getErrorMessage());
                        Scores.isFriendsScoresLoaded = false;
                    } else {
                        Log.d("getting all scores",
                                "Got Scores successfully from Facebook");
                        Log.d("score object", response.getGraphObject()
                                .getInnerJSONObject().toString());
                        Scores.isFriendsScoresLoaded = true;

                    }

                }
            });
    Request.executeBatchAsync(postScoreRequest);
}