How to get the user score value from Google Play Services Leaderboard?

I know this is the basic of posting the score :

Social.ReportScore(TheScore, "LeaderboardID", (bool success) => {
        // handle success or failure
        });

But how do I “get” the score to be displayed again within the game? the problem is that whenever I update my app on Play Store, the local score returns to “0”, but the ones on the Google Play Service Leaderboard is still intact, so I am looking for a way to get that Leaderboard value back to the game.

thx :slight_smile:

For those of you who are trying to get the leaderboard score from Google Play try this code after you’re authenticated:

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

Basically, data.PlayerScore.UserID will give you the player’s unique ID, data.PlayerScore.formattedValue will give you the highest score of the player that was submitted to the Google Play leaderboards. data.Id will give you the leaderboard ID and so on.

Seriously, this is not a Unity question, its a Google one.

The STARTING page of the Google Dev quickstart deals with Achievements and leaderboards.

Do the sample project. It will take half an hour. By the end of it you will know how leaderboards work and how to use them in your project.

You have to call Leader biard display methodt o get the Leader board score on your game.

  1. Set up you leader biard on Google Play Game Service. just go through. Leaderboards  |  Play Games Services  |  Google for Developers
  2. Use the Google play Plugins : GitHub - playgameservices/play-games-plugin-for-unity: Google Play Games plugin for Unity

You can use the following method to call leader board. It is working in my case.

using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;

public class _GameCenterManager : MonoBehaviour {
	  
	// Use this for initialization
	void Start () {

		
		AuthonicatePlayer();

	}


	private void AuthonicatePlayer(){

		PlayGamesPlatform.DebugLogEnabled = true;
		PlayGamesPlatform.Activate();
		
		Social.Active.localUser.Authenticate(ProcessAuthentiation);
		Debug.Log("Login Process ...");

	}



	// Call this method on Show Achievement Button action 

	public void GC_ReportAchievementScore(){

 
		if(PlayerPrefs.GetInt ("Hero")> 0){

			SubmitAchievementProgress("Achievement ID Here");
		}
		Social.ShowAchievementsUI();
		
	}


	void SubmitAchievementProgress(string MyID){

		Social.ReportProgress(MyID, 100.0f, (bool success) => {
			
			
			if(success){
				
				print("successfully reported Achievement");
			}else{
				
				print("Something... wrong on report score");
			}
		} );
	}

	 
	// Call this method on Show Leaderboard Button action 


	public void GC_ReportHighScore(){

			
		long currentScore = PlayerPrefs.GetInt ("TotalScore");
		Social.ReportScore(currentScore, "Your Leader Board ID", (bool success) => {
			// handle success or failure
			
			if(success){
				
				print ("successfully reported");

			}else{
				
				print("Something... wrong on report score");
			}
		} );

		((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("Your Leader Board ID");


	}
 
	
	// Update is called once per frame
	void Update () {
	}

	void ProcessAuthentiation(bool success)
	{
		if (success)
		{
			print("successfully authonicated");
		}
		else
		{
			print("fail to authonicate");
		}
	}

}

I’m having the same problem, unfortunately the plugin says this functionality is not supported yet :frowning:
alt text

public void loadTopLeaderboardScores(string leaderboardId, int span, int leaderboardCollection, int maxResults,bool forceReload)

Asynchronously load the top page of scores for a given leaderboard.

https://github.com/unity-plugins/google-service-unity/wiki/Unity-Google-Game-API#public-void-loadtopleaderboardscoresstring-leaderboardid-int-span-int-leaderboardcollection-int-maxresultsbool-forcereload

@Ronggowisnu Not sure if you are still interested, but this worked for me using the latest Google Play Games Unity plug-in:

using GooglePlayGames;
using GooglePlayGames.BasicApi;

PlayGamesPlatform.Instance.LoadScores("leaderboard_ID",
    				LeaderboardStart.PlayerCentered,
    				1,
    				LeaderboardCollection.Public,
    				LeaderboardTimeSpan.AllTime,
    				(LeaderboardScoreData data) => {
    					DisplayText.text = "You have " + data.PlayerScore.formattedValue + " points!";
    				} 
    			);

What it is doing basically is loading the scores from the Leaderboard you identify, centered on the player, and only collecting one row (1), looking at the public leaderboard, all time scores.

It then returns data, of which you collect the PlayerScore portion, and use the formattedValue as that represents legible values (ie: 1, 25, 547, etc…). Since you only collected that one row of data you only have the one player’s score.

Hi there is way to show custom google play leaderboard
I have implemented in our game Up : Adventure time
https://play.google.com/store/apps/details?id=com.aaryavarta.up

but it has several issues. Global Leaderboard fetch only few users from the entire list of users.
its showing 1242 users but only fetch 12 users list

I have used following plugin.

Vidaris code is working perfectly i don’t know why peoples are discussing it further?

remove the bracket <> if you are confused

This work for me on Feb 2021

    ILeaderboard leaderboard = Social.CreateLeaderboard();
    leaderboard.timeScope = TimeScope.AllTime;

    leaderboard.id = "YOUR_APP_LEADERBORAD_ID";
    leaderboard.LoadScores(success =>
    {
        if (success)
        { 
            // you can retrieve the score of local user here
            long localUserScore = leaderboard.localUserScore.value;
        }
    });