Google Play游戏C ++ API - 无法以编程方式访问好友

时间:2017-02-02 22:06:26

标签: android c++ google-play-games

Google Play游戏C ++似乎没有为我返回正确的朋友数据。

这里的基本想法是我们在游戏中有一个显示朋友分数列表的页面。此外,当您正在玩游戏时,它会在您接近时以及当您传递朋友的最佳分数时在屏幕上显示指示符。

游戏是用Cocos2d-x编写的,因此我们使用的是Google Play游戏C ++库。 GPG成功进行身份验证,其他功能(例如解锁成就和实际提交分数)正常运行。顺便说一句,如果谷歌的任何人正在阅读,网站上有版本2.2的发行说明,但下载页面只有2.1,这就是我们正在使用的。

无论如何,我们有两个不同的Google Play帐户设备是朋友。我们可以选择打开默认的本地游戏服务排行榜UI,如果我进入社交排行榜,那么这两个设备都会从此页面看到其他玩家的高分 - 所以我们似乎已经成功地让两个帐户成为朋友。 / p>

不幸的是,我无法使用C ++ API以编程方式获取此朋友数据。

以下是相关代码。

void GameCenterSession::fetchFriends()
{
    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Fetching friends!");

    //GET INVITABLE FRIENDS
    game_services_->Players().FetchInvitable(gpg::DataSource::CACHE_OR_NETWORK, [] (gpg::PlayerManager::FetchListResponse response) {
        __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Got invitable friends response: %d", response.status);
        __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Got invitable players info! Num players: %d", response.data.size());
        if (gpg::IsSuccess(response.status)) {
            //PROCESS PLAYERS
            GameCenterSession::getInstance()->onPlayersInfoReceived(kRequestFriendsInfo, response.data);
        }
    });

    //GET CONNECTED FRIENDS
    game_services_->Players().FetchConnected(gpg::DataSource::CACHE_OR_NETWORK, [] (gpg::PlayerManager::FetchListResponse response) {
        __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Got connected friends response: %d", response.status);
        __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Got connected players info! Num players: %d", response.data.size());
    });
}

void GameCenterSession::onPlayersInfoReceived(const int requestId, std::vector<gpg::Player> playersInfo) {

    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "onPlayersInfoReceived num players: %d", playersInfo.size());
    const gpg::ScorePage::ScorePageToken distanceToken = game_services_->Leaderboards().ScorePageToken(
        kLeaderboardBestDistance,
        gpg::LeaderboardStart::TOP_SCORES,
        gpg::LeaderboardTimeSpan::ALL_TIME,
        gpg::LeaderboardCollection::SOCIAL
    );

    //FETCH ALL TIME SOCIAL SCORES FOR DISTANCE
    game_services_->Leaderboards().FetchScorePage(gpg::DataSource::CACHE_OR_NETWORK, distanceToken, 1000, [] (gpg::LeaderboardManager::FetchScorePageResponse response) {

        if (gpg::IsSuccess(response.status) && response.data.Valid()) {
            __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Got social leaderboard! Num players: %d", response.data.Entries().size());
            gpg::ScorePage::Entry myEntry = gpg::ScorePage::Entry();

            //search through and find my score!
            for (auto score : response.data.Entries()) {
                __android_log_print(ANDROID_LOG_INFO, "MyGame!", "%s got distance %d", score.PlayerId().c_str(), score.Score().Value());


                if (score.PlayerId().compare(GameCenterSession::getInstance()->myPlayer.Id()) == 0) {
                    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Distance - Yup that's me");
                    myEntry = score;
                } else {
                    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Distance - It's another player!");
                }
            }

            GameCenterSession::getInstance()->onScoresReceived(kRequestFriendsDistancesInfo, myEntry, response.data.Entries());
        }
    });


    const gpg::ScorePage::ScorePageToken scoreToken = game_services_->Leaderboards().ScorePageToken(
        kLeaderboardBestScore,
        gpg::LeaderboardStart::TOP_SCORES,
        gpg::LeaderboardTimeSpan::ALL_TIME,
        gpg::LeaderboardCollection::SOCIAL
    );

    game_services_->Leaderboards().FetchScorePage(gpg::DataSource::CACHE_OR_NETWORK, scoreToken, 1000, [] (gpg::LeaderboardManager::FetchScorePageResponse response) {
        if (gpg::IsSuccess(response.status) && response.data.Valid()) {

            gpg::ScorePage::Entry myEntry = gpg::ScorePage::Entry();

            //search through and find my score!
            for (auto score : response.data.Entries()) {
                __android_log_print(ANDROID_LOG_INFO, "MyGame!", "%s got score %d", score.PlayerId().c_str(), score.Score().Value());


                if (score.PlayerId().compare(GameCenterSession::getInstance()->myPlayer.Id()) == 0) {
                    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Score - Yup that's me");
                    myEntry = score;
                } else {
                    __android_log_print(ANDROID_LOG_INFO, "MyGame!", "Score - It's another player!");
                }
            }

            GameCenterSession::getInstance()->onScoresReceived(kRequestFriendsScoresInfo, myEntry, response.data.Entries());
        }
    });

    if (requestId == kRequestFriendsInfo)
    {
        friends = playersInfo;
    }
}

查看代码,您会看到我首先获取好友列表并查看该列表中有多少玩家。我尝试访问两个邀请的朋友(通过文档来判断这是我想要的那个)和连接的朋友(仅作为测试)。我继续抓住两个不同的所有时间社交排行榜 - 距离和得分,我检查结果中有多少玩家。这是我的日志输出。

//设备1

I/MyGame!( 1510): Google Play Games authenticated successfully!
I/MyGame!( 1510): Fetching friends!
I/MyGame!( 1510): Got invitable friends response: 1
I/MyGame!( 1510): Got invitable players info! Num players: 0
I/MyGame!( 1510): onPlayersInfoReceived num players: 0
I/MyGame!( 1510): Got connected friends response: 1
I/MyGame!( 1510): Got connected players info! Num players: 0
I/MyGame!( 1510): Got social leaderboard! Num players: 1
I/MyGame!( 1510): g1703186947466536XXXX got distance 310
I/MyGame!( 1510): Distance - Yup that's me
I/MyGame!( 1510): g1703186947466536XXXX got score 2510
I/MyGame!( 1510): Score - Yup that's me

//设备2

01-23 17:11:27.227 17187 17234 I MyGame!: Google Play Games authenticated successfully!
01-23 17:11:27.250 17187 17234 I MyGame!: Fetching friends!
01-23 17:11:27.451 17187 17234 I MyGame!: Got invitable friends response: 1
01-23 17:11:27.451 17187 17234 I MyGame!: Got invitable players info! Num players: 0
01-23 17:11:27.451 17187 17234 I MyGame!: onPlayersInfoReceived num players: 0
01-23 17:11:27.581 17187 17234 I MyGame!: Got connected friends response: 1
01-23 17:11:27.581 17187 17234 I MyGame!: Got connected players info! Num players: 0
01-23 17:11:27.973 17187 17234 I MyGame!: Got social leaderboard! Num players: 1
01-23 17:11:27.973 17187 17234 I MyGame!: g0152008166550356XXXX got distance 712
01-23 17:11:27.973 17187 17234 I MyGame!: Distance - Yup that's me
01-23 17:11:28.444 17187 17234 I MyGame!: g0152008166550356XXXX got score 2142
01-23 17:11:28.444 17187 17234 I MyGame!: Score - Yup that's me

如您所见,我的回调都返回成功的结果代码。不幸的是,两个设备都没有返回任何朋友,社交排行榜回调只包含设备上的播放器,而不是朋友的分数。

我尽可能地遵循文档,并且我已经查看了代码而没有找到任何问题,但如果它只是一个语义问题,我会很高兴听到我的错误。我在这里做错了什么,或者C ++ API本身有问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

API的行为符合预期。来自:https://android-developers.googleblog.com/2016/12/games-authentication-adopting-google.html

不再集成Google+ Announced last year,游戏在此过渡期间与Google+脱钩。因此,通过圈子获取连接玩家的公共API停止工作,但多人邀请和社交排行榜的标准UI继续有效。从2017年2月开始,标准用户界面也不会显示社交图表结果,因为Google+数据无法访问。这将影响Android上的多人游戏,社交排行榜和礼品API。效果将是这些API将成功返回,但是有一个空的播放列表。

相关问题