2017-02-02 20 views
0

Google Play游戏C++似乎并没有为我返回正确的朋友数据。Google Play游戏C++ API - 无法以编程方式访问朋友

这里的基本思路是我们在游戏中有一个页面,显示朋友分数列表。此外,当你玩游戏时,它会在屏幕上显示一个指标,当你接近和当你通过你的朋友的最好成绩。

该游戏是用Cocos2d-x编写的,因此我们使用Google Play游戏C++库。 GPG认证成功,其他功能(如解锁成就和实际提交分数)工作正常。顺便说一句,如果Google的任何人都在阅读,那么网站上就有版本说明2.2版,但下载页面只有2.1版,所以这就是我们正在使用的版本。

无论如何,我们有两个设备与不同的Google Play帐户是朋友。我们可以选择打开默认的原生游戏服务排行榜界面,如果我转到社交排行榜,那么这两个设备都会从该页面看到其他玩家的高分 - 所以看起来我们已经成功创建了这两个帐户的朋友。

不幸的是,我无法使用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本身有问题吗?

在此先感谢。

回答

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将成功返回,但是会有一个空的玩家列表。

+0

感谢您的回复。我看到你是这篇博客文章的作者,所以我恳请要求在相关文档中添加一条说明,说明此功能不再有效。我们花了很多时间来实现和调试这些,我没有看到任何提到这些功能在查看链接的博客文章之前不再有效。再次感谢。 – noodleben

相关问题