Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I can't get google play services to work (leaderboard)

Discussion in 'Scripting' started by saywow, Oct 6, 2017.

  1. saywow

    saywow

    Joined:
    Jul 31, 2017
    Posts:
    9
    Hi,

    I'm trying to add leaderboard to my google play game, to do so I have :
    1) Downloaded the plugin from here : https://github.com/playgameservices/play-games-plugin-for-unity
    2) Uploaded my game here : https://play.google.com/apps/publish after filling the required data and creating keystroke etc...
    3) added a new game to game services and created leaderboard inside, then copied the resources to my android setup (in unity)
    4) published the game as alpha and added my account as alpha tester
    5) downloaded the game from play store on my phone
    now whenever I test it, it just show the login modal for few seconds (sometimes it asks me to pick the email) then it disappears and nothing happens after that, can any one help please ?
    here is my code :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using GooglePlayGames;
    6. using GooglePlayGames.BasicApi;
    7. using UnityEngine.SocialPlatforms;
    8.  
    9. public class LeaderBoardManager : MonoBehaviour {
    10.  
    11.     public static LeaderBoardManager instance;
    12.  
    13.     void Awake()
    14.     {
    15.         if (instance == null)
    16.             instance = this;
    17.     }
    18.  
    19.     // Use this for initialization
    20.     // Use this for initialization
    21.     void Start()
    22.     {
    23.         PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    24.         // enables saving game progress.
    25.         .EnableSavedGames()
    26.         // requests the email address of the player be available.
    27.         // Will bring up a prompt for consent.
    28.         .RequestEmail()
    29.         // requests a server auth code be generated so it can be passed to an
    30.         //  associated back end server application and exchanged for an OAuth token.
    31.         .RequestServerAuthCode(false)
    32.         // requests an ID token be generated.  This OAuth token can be used to
    33.         //  identify the player to other services such as Firebase.
    34.         .RequestIdToken()
    35.         .Build();
    36.  
    37.         PlayGamesPlatform.InitializeInstance(config);
    38.         // recommended for debugging:
    39.         PlayGamesPlatform.DebugLogEnabled = true;
    40.         // Activate the Google Play Games platform
    41.         PlayGamesPlatform.Activate();
    42.         SignIn();
    43.     }
    44.  
    45.  
    46.     // Update is called once per frame
    47.     void Update () {
    48.      
    49.     }
    50.  
    51.     void SignIn()
    52.     {
    53.         Social.localUser.Authenticate((bool success) =>
    54.         {
    55.             if (success)
    56.             {
    57.                 Debug.Log("Login Sucess");
    58.             }
    59.             else
    60.             {
    61.                 Debug.Log("Login failed");
    62.             }
    63.         });
    64.     }
    65.  
    66.     public void AddNewScore()
    67.     {
    68.         Social.ReportScore(ScoreManager.instance.score, LeaderBoard.leaderboard_scores, (bool success) => {
    69.  
    70.         });
    71.     }
    72.  
    73.     public void ShowLeaderBoard()
    74.     {
    75.         PlayGamesPlatform.Instance.ShowLeaderboardUI(LeaderBoard.leaderboard_scores);
    76.     }
    77. }
    78.  
    I'm calling the method ShowLeaderBoard when a user clicks on a certain button (I know I must check if the user is logged in first, but I'm calling sign in in the start method, i tried both methods but none of them is working)

    anyone can help please ?

    EDIT : I found this error in the logs:
    Application ID [my_app_id] is not associated with package [my_package]. Check the application ID in your manifest.
     
    Last edited: Oct 6, 2017
  2. saywow

    saywow

    Joined:
    Jul 31, 2017
    Posts:
    9
    I have followed every single tutorial I found on the net, always the same problem, the best I could get is being able to login but the leaderboard doesn't show please help !

    The logs when login works but not the leaderboard:
     
  3. saywow

    saywow

    Joined:
    Jul 31, 2017
    Posts:
    9
  4. ManojBalaji

    ManojBalaji

    Joined:
    Feb 22, 2017
    Posts:
    3
    i am also trying to work on leaderboard i failed in all attempts. can you please guide me how to do work on leaderboard?
     
  5. mliukka

    mliukka

    Joined:
    Nov 1, 2015
    Posts:
    19
    There's one thing worth trying: in case you're using two different Google accounts to develop and to test the game on your phone, you need to manually add your gmail as a tester. I have a personal gmail I'm using on my phone and a DIFFERENT gmail to log on my developer account, so for that simple reason couldn't get the authentication to finish on my phone. Your developer account is added as a tester automatically but any additional testers have to be added manually. This could be the reason why for some people it never works during testing but does work after publishing.

    http://answers.unity.com/answers/1532378/view.html
     
  6. Mexaa

    Mexaa

    Joined:
    Apr 21, 2018
    Posts:
    2
    Hello, i'am also having a similar problem.
    If i do a build and run in unity, the leader board works perfectly. But after i publish the game in internal test it doesn't display anything anymore. I download it from google play store, and it doesn't display anything. Does anyone know why?
    Thank you
     
  7. Mhietos

    Mhietos

    Joined:
    Jul 5, 2018
    Posts:
    1
    If you didnt try it yet, you have to enter your email in your app release but also in your game services
     
  8. Kruemelchen

    Kruemelchen

    Joined:
    Aug 26, 2019
    Posts:
    27
    Hi, after weeks of rage and despair I've given up on implementing the google play leaderboards. As suddenly one of my user found out how to make the leaderboard work...

    First of all: the first pitfall for me was to recognize that now there is a new way how apps are being signed. Google only allows to upload .aab-bundles since August 2019. Unity's key signing is applied to the bundle BUT since aab is distributed as different apks for different architectures by the store itself, there is an additional key signing!
    So you have to ensure that the oauth in the developer console uses the hash of the singing made BY THE STORE. Not by Unity.. Thanks to google you can read this in the documentation.. NOT..

    So far so good. The user were able to use Google Play but still no leaderboard for them. They could saw my personal (developer) score but couldn't submit their own. The error always was some cryptic "ERROR Code 3" stuff which - according to the documentation - was due to singing problems.
    So I switched plugin versions and also switched from Ultimate Mobile Asset Pack back to the official Google Play Unity SKD.. but still no difference..
    After weeks of despair I finally gave up. No Google Play Services ever again!!

    Some weeks later an user made an observation.. to submit your score, you as an user, have to explicitly allow google to show your activity publicly. To enable this, you have to go to google play (not the play store) and enable in the settings, that everyone can see your activity... oh boy..

    I have to say, that nothing else was EVER a bigger pain to implement that google play services.
     
    Serge144 and Doomgriever like this.
  9. Doomgriever

    Doomgriever

    Joined:
    May 19, 2013
    Posts:
    5
    Wow, thank you!

    A week later and my score finally shows up... Here I thought my code was wrong, nope you have to enable public visibility to your Google Play profile *facepalm*. Sure wish it would state somewhere in the documentation.

    I've implemented Steam API and Nintendo Switch before, but yes GPS has been a real pain. Almost everything is working now after many many tutorials and countless forum searches.
     
    Serge144 likes this.
  10. Serge144

    Serge144

    Joined:
    Oct 2, 2018
    Posts:
    64
    I'm totally with you... after a bit of testing I was coming to the conclusion that by uploading an AAB or even APK the Google Play is signing with its own key to the Internal test tracks. If I just sign with my key and install directly to my phone, the leaderboards show. Can you tell me how did you got the Google Plays Store signing key information? Thank you in advance.
     
  11. Serge144

    Serge144

    Joined:
    Oct 2, 2018
    Posts:
    64
    Good to know!
     
  12. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    85
    I'm confused about this... Nowhere in the google play developer console can I find anything about this "oauth". They only 'signing' part done was the keystore signing under "publishing settings" in unity, which either fails or succeeds. If succesful, google play accepts the app as valid, but that doesn't have anything to do with leaderboards, does it?
     
  13. tangyinglin0228

    tangyinglin0228

    Joined:
    Apr 23, 2018
    Posts:
    16
    I am struggling too. When I checked the Development Build, I could see the leaderboard and post scores. But when I uncheck the Development build. I could not even sign in. So, I don't know if it would work in live version. Although I don't have any users yet.