• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by WILEz1975 · Aug 12, 2017 at 03:28 PM · google play gamesleaderboards

How to get user names in google play game services leaderboard

I need help in getting the player nickname of the players in the leaderboards. When I use loadScores, I only get the playerID (w$$anonymous$$ch is a string numbers), with t$$anonymous$$s code:

       PlayGamesPlatform.Instance.LoadScores (
                  <your_leaderboard_ID_here>,
                  LeaderboardStart.PlayerCentered,
                  1,
                  LeaderboardCollection.Public,
                  LeaderboardTimeSpan.AllTime,
              (LeaderboardScoreData data) => {
                  Debug.Log (data.Valid);
                  Debug.Log (data.Id);
                  Debug.Log (data.PlayerScore);
                  Debug.Log (data.PlayerScore.userID);
                  Debug.Log (data.PlayerScore.formattedValue);
 
   //1°
   FirstNickName.text = data.Scores[0].userID;
   //2°
   SecondNickName.text = data.Scores[1].userID;
   //3°
   T$$anonymous$$rdNickName.text = data.Scores[2].userID;
 
              });
          }


Work fine for all the player id's, all ranks and scores... and for the logged user name, but not for all player names in the leaderboard. I tried to use loadPlayers and use alias, it doesn't give me anyt$$anonymous$$ng. I can successfully logged in in google play game services.

I need t$$anonymous$$s like:

  //1
  FirstNickName.text = data.Scores[0].userName;
  //2
  SecondNickName.text = data.Scores[1].userName;
  //3
  T$$anonymous$$rdNickName.text = data.Scores[2].userName;

etc...

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image

Answer by hypercry · Dec 01, 2018 at 11:55 AM

I wonder how it was done. We wish you to respond as soon as possible ...

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by WILEz1975 · Sep 21, 2019 at 02:28 PM

It has been done. But many years have passed by now and I don't remember how I did it. No answer had here :(

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Dawdlebird · Feb 24, 2020 at 03:27 PM

In case anyone is looking for t$$anonymous$$s: it seems you'll need to do t$$anonymous$$s in a separate step. Loadscores gives you a list of userID's, w$$anonymous$$ch you cast into "string[] userIDs " for example. Then use Social.LoadUsers(userIDS, =>...) to have somet$$anonymous$$ng done with t$$anonymous$$s info.

I've used t$$anonymous$$s as follows (more or less:

 // get scores
 IScore[] scores = data.Scores;
 // get user ids
 string[] userIds = new string[scores.Length];
         for (int i = 0; i < scores.Length; i++)
         {
             userIds[i] = scores[i].userID;
         }
 // forward scores with loaded profiles
 Social.LoadUsers(userIds, profiles => DisplayLeaderboardEntries(scores, profiles));

The "DisplayLeaderboardEntries" will be called after users have been loaded, so you will have both scores(and ranks) and profile info (name, icon) available to display in whatever way you like.

Comment
Meneghetti
UnityIco
EpicWolffe

People who like this

3 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by thedetective456 · Oct 02, 2020 at 05:58 AM

For anyone wondering how to get user data from leaderboard. First authenticate the player and then load scores. Use

     var lb = PlayGamesPlatform.Instance.CreateLeaderboard(); // Create leaderboard
     lb.id = Leaderboards.PerfectLevels.ID; // assign ID to it

     PlayGamesPlatform.Instance.LoadScores(
         lb.id, // Leaderboard ID
         LeaderboardStart.PlayerCentered, // Get from top scores or player centered
         5, // number of rows of scores you want
         LeaderboardCollection.Public, // public scores or social
         LeaderboardTimeSpan.AllTime, // Time span
         (LeaderboardScoreData data) => // callback with scores
         {                
             for(int i = 0; i < data.Scores.Length; i++)
             {
                 Debug.Log("Player User name : " + data.Scores[i].userID);
                 Debug.Log("Player score : " + data.Scores[i].formattedValue);
                 Debug.Log("Player Rank : " + data.Scores[i].rank.ToString());
             }            
         }
     );

@WILEz1975 did a mistake, in number of rows to return, he had passed 1 -> only player score was returning.

Also if you specifically need Player data, just use "data.PlayerScore" instead of a for loop and "data.Scores"

Hope t$$anonymous$$s helps :)

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

116 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Open a Spesific LeaderBoard using Google Play Services 0 Answers

Google Play and Facebook leaderboards 0 Answers

google play get score from leaderboard 3 Answers

Why isn't this script posting the score to Google Play Leaderboards? 2 Answers

How to detect a sign-out from Google Play achievements or leader-boards UI ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges