简体   繁体   English

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

[英]facebook sdk 3.0 getting friends scores return empty (android)

im trying to use facebook's score api. 我试图使用Facebook的得分API。

so i'm posting the score like this: 所以我发布这样的分数:

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);
}

success! 成功!

and im getting the users score like this: 并即时获得用户评分,如下所示:

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);
}

success!!! 成功!!!

BUT when im trying to get all of friends scores, like this: 但是当我试图获得所有朋友的分数时,像这样:

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 WORKS! * 它工作! (NO ERROR ) BUT IT RETURNES AN EMPTY JASON :( * (无错误)但返回空杰森:( *

thank you for the help!!!! 感谢您的帮助!!!!

Yakir. 亚基尔

You are so close 你好亲近

You don't need the first forward slash and you were passing the resourceID instead of the actual App IP. 您不需要第一个正斜杠,并且您传递的是resourceID而不是实际的App IP。 So the updated code will look like this.. 因此更新后的代码将如下所示。

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM