Able to log in Google Play Games, but not showing Leaderboard - android

We are developing a smartphone game with my team on Unity, and I'm currently trying to implement Google Play Games in our game, without success.
Right now, the user can log in without issues (popup showing, and logcat says it's ok), but I can't figure why the leaderboard won't show... According to the logcat, the request for the leaderboard seems ok, but no return/error.
I don't think the fault is on Unity side, as the code is the same as the exemple provided by Google :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_ANDROID
using GooglePlayGames;
using GooglePlayGames.BasicApi;
#endif
using UnityEngine.SocialPlatforms;
public class PlayGameServices_func : MonoBehaviour
{
void Start ()
{
#if UNITY_ANDROID
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestEmail()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
#endif
}
public void ShowLeaderboards()
{
PlayGamesPlatform.Instance.ShowLeaderboardUI();
}
public void SignIn ()
{
PlayGamesPlatform.Instance.Authenticate ((bool success) => {
if (success)
Debug.Log("Successfuly signed in!");
else
Debug.Log("Sign in failed...");
});
}
void SignInCallback (bool success)
{
if (success)
Debug.Log("Successfuly signed in!");
else
Debug.Log("Sign in failed...");
}
}
I think the problem is on Google Developer Console's side, but after 5 days of searching/experimenting/etc... I wasn't able to find a solution.
Can somebody help me?
Have a nice day !

Related

App is crashing while using play games services in unity project

i am trying to use play games services plugin for unity i have done everything correctly but whenever i am testing it using build and run into my android device it starts to crash but whenever i am removing SignIn(); from start function it's working fine. and also i don't see any sign in window.
my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
public class PlayServices : MonoBehaviour
{
// Use this for initialization
void Start ()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();
SignIn();
}
public void SignIn()
{
PlayGamesPlatform.Instance.localUser.Authenticate((bool success) => {
if(success){
Debug.Log("Sign in");
}
else
{
Debug.Log("Unable to Sign in");
}
});
}
}

Play Games login all times (android/unity)

I have try to add Play Games into my game (on android). I have add my APP in Play Store Dev, and create a game on it.
Now, i use the SDK of google, i have configure it.
The problem is :
- When i launch my game, they ask me all time to login. I want save if the user is loggin or not.
- The leaderboard didn't show when i click on my button, they just ask to login.
For my leaderboard:
Social.localUser.Authenticate ((bool success) => {
Social.ShowLeaderboardUI();
});
For ADD a score
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class MenuGameOver : MonoBehaviour
{
public Text level;
public Text score;
public Text bestScore;
public GameObject newBestScoreLabel;
void OnEnable(){
level.text = ScoreManager.GetLastLevel ().ToString ();
score.text = ScoreManager.GetLastScore ().ToString ();
bestScore.text = ScoreManager.GetBestScore ().ToString ();
bool isNewBest = ScoreManager.GetLastScoreIsBest ();
if (isNewBest) {
newBestScoreLabel.SetActive (true);
} else {
newBestScoreLabel.SetActive (false);
}
Social.ReportScore(1234, "XX", (bool success) => {
});
}
}
When i launch my game:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
// enables saving game progress.
.EnableSavedGames()
// require access to a player's Google+ social graph to sign in
.RequireGooglePlus()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();
if(Social.localUser.authenticated){
Social.ShowLeaderboardUI();
}else{
Social.localUser.Authenticate ((bool success) => {
if(success){
//yay
}
});
}
Remember Social.localUser.Authenticate is to authenticate or login. You are calling it on show leaderboard button. So it will definitely prompt for login. Nothing strange in it. Your line of code is used to check if user is not authenticated before then first login and then show leaderboard.
What you can do is to simply authenticate at launch.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
// enables saving game progress.
.EnableSavedGames()
// require access to a player's Google+ social graph to sign in
.RequireGooglePlus()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();
Social.localUser.Authenticate ((bool success) => {
if (success)
print("GPGS authenticated successfully");
});
And on Leaderboard button you have to call just show leaderboard if user is authenticated otherwise login first then show leaderboard.
//On Leaderboard button
if(Social.localUser.authenticated){
Social.ShowLeaderboardUI();
}
else
Social.localUser.Authenticate ((bool success) => {
if (success)
Social.ShowLeaderboardUI();
});

Can not connect to Google Game services [duplicate]

I am developing an Android application where I want to use the Google API. For that I have imported the google-play-service-lib project.
I am following this link to initialize GoogleApiClient object.
My code:
1) In the onCreate() method I am building the GoogleApiClient object:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) In onStart(), I call mGoogleApiClient.connect().
3) My activity implements
ConnectionCallbacks and OnConnectionFailedListener.
4) My onConnectionFailed() method looks like:
public void onConnectionFailed(ConnectionResult result) {
//in dubug result looks like : ConnectionResult{
//statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
// {41f8ca70: android.os.BinderProxy#41f8ca10}}
try {
if(!mIntentInProgress && result.hasResolution())
{
mIntentInProgress=true;
result.startResolutionForResult(mActivity, RC_SIGN_IN);
}
} catch (SendIntentException e) {
e.printStackTrace();
}
}
5) My onActivityResult() method contains:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
When I run my app I get a Toast that says that an internal error popped up. I did create the project in the Google console.
I had the same problem.
From documentation:
The client may choose to continue without using the API or it may call startResolutionForResult(Activity, int) to prompt the user to sign in.
So you should try to sign in by using startResolutionForResult() function
#Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}
Just follow google's instructionss
AND CAUTION
Since you are still in development mode, check if you have added your testing email address in the GAME DETAILS center before publishing the game.
Check that you are signing the app with a keystore that is in the apk uploaded to Google Play Developer's Console (if testing, you can upload as alpha and publish while keeping it private).
If not this, it could be other things. Make sure your account's email address is listed in testers in the Account details page (on the settings menu with a gear icon), and the licensed response is set to LICENSED, NOT to RESPOND_NORMALLY
This error indicates that the user needs to authorize your app. There's a full workflow for this, following the tutorial at https://developers.google.com/+/mobile/android/getting-started look for "onConnectionFailed"
Drive api should be enabled from the console page.
Not sure if this is the best answer but it worked for me. I copied onConnectionFailed() from the BasicSamples TakeANumber MainActivity. It calls BaseGameUtils to resolve. Of course that implies you have the BaseGameUtils library included in your project and that's another can of worms. But maybe you can get by with the one method so I copied it below.
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
logger.info( "onConnectionFailed() *play* : attempting to resolve");
if (mResolvingConnectionFailure) {
logger.info( "onConnectionFailed(): already resolving");
return;
}
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
}
From Google BasicSamples BaseGameUtils.java:
public static boolean resolveConnectionFailure(Activity activity,
GoogleApiClient client, ConnectionResult result, int requestCode,
String fallbackErrorMessage) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(activity, requestCode);
return true;
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
client.connect();
return false;
}
} else {
// not resolvable... so show an error message
int errorCode = result.getErrorCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
activity, requestCode);
if (dialog != null) {
dialog.show();
} else {
// no built-in dialog: show the fallback error message
showAlert(activity, fallbackErrorMessage);
}
return false;
}
}
if you are not using debug keys, push app to google play as alpha, add yourself as a tester and MOST important - follow the "Opt-in" link on Aplha page and CONFIRM that you are the tester.
I'd like to share my experience with this. My case was when using Google Play Services for Google Play Games. I was also getting the onConnectionFailed giving SIGN_IN_REQUIRED error. Finally I realize I had not "Published" my Game settings in the developer console. Not to be mistaken for publishing an "alpha" or "beta" version of your apk. I mean the actual Google Play Games "Game" you create and link to the game's APK.
I had Same problem and solved with this solution ,
I actually had very old version google play-services library so I updated It with latest google play-service library to compile 'com.google.android.gms:play-services:11.0.4' from my previous version library to support your android SDK and maintain compileSDKVersion and targetSDKVersion in gradle:app.
add google drive enabled API_KEY in manifest.and try again
In my case the problem was in sensitive scopes added and not verified:
https://console.developers.google.com/apis/credentials
Credentials -> OAuth consent screen -> Scopes for Google APIs
Make sure you have no unverified scopes.
for my cause i wrongly used release SHA1 key to generate API in developer console.
Then created SHA1 key with debug.keystore and updated in my api credentials.
Its started working.
keytool -list -v -keystore "C:\Users\<user>n\.android\debug.keystore" -alias androiddebugkey -storepass andro
id -keypass android

Google play services doesnt displays leaderboard after Auth

Its a very weird have invested a lot of time in this. So asking here.
I am using this plugin and followed the steps https://github.com/playgameservices/play-games-plugin-for-unity
I just want to use Google play services in release mode for leaderboard only (i am using in alpha launch)
Here is my code for Auth in GPlay services :
void Awake(){
PlayerPrefs.SetInt("GameOverCount",0);
#if UNITY_ANDROID
Authenticate ();
#endif}
I have configured Gplay setup by providing 10+ digit Client ID
I have generated OAuth Client ID from Google APis using SHA1 of release.keystore that i am using.
In Gplay service in DEveloper console : I have published the linked apps without any errors
public void Authenticate() {
if (Authenticated || mAuthenticating) {
Debug.LogWarning("Ignoring repeated call to Authenticate().");
return;
}
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// Activate the Play Games platform. This will make it the default
// implementation of Social.Active
PlayGamesPlatform.Activate();
// Set the default leaderboard for the leaderboards UI
((PlayGamesPlatform) Social.Active).SetDefaultLeaderboardForUI(leaderboardID_android);
// Sign in to Google Play Games
mAuthenticating = true;
Social.localUser.Authenticate((bool success) => {
mAuthenticating = false;
if (success) {
UnityAnalytics.CustomEvent("Auth Completed", new Dictionary<string, object>
{
{ "isAuthDone", true }
});
if(showScores){
Social.Active.ShowLeaderboardUI();
Debug.Log("should show leaderborad");
}
// if we signed in successfully, load data from cloud
Debug.Log("Login successful!");
} else {
// no need to show error message (error messages are shown automatically
// by plugin)
Debug.LogWarning("Failed to sign in with Google Play Games.");
UnityAnalytics.CustomEvent("Auth Failed", new Dictionary<string, object>
{
{ "isAuthDone", false }
});
}
});
}
#if UNITY_ANDROID
if (Authenticated) {
showScores = false;
((PlayGamesPlatform)Social.Active).ShowLeaderboardUI(leaderboardID_android);
Social.ShowLeaderboardUI();
Debug.Log("should show leaderborad");
UnityAnalytics.CustomEvent("Authenticated and show android leaderboard", new Dictionary<string, object>
{
{ "isShowing", true }
});
}else{
showScores = true;
Authenticate();
}
#endif
Next, i release the alpha and check on android devices - i get a screen saying connecting to google play games...connects processes and then goes off the screen.
It seems like it authenticates and goes off. But doesn't displays leaderboard for some reason. I am not able to understand why its happening and what's missing.
In my unity analytics, only once scores aren't loaded and i played it 20-30 times :
In my Developer console, Number of scores is empty :
Can anybody pls help in this, i can provide more details to people who can help / want to help....Thanks...

onConnectionFailed giving SIGN_IN_REQUIRED(4)

I am developing an Android application where I want to use the Google API. For that I have imported the google-play-service-lib project.
I am following this link to initialize GoogleApiClient object.
My code:
1) In the onCreate() method I am building the GoogleApiClient object:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
2) In onStart(), I call mGoogleApiClient.connect().
3) My activity implements
ConnectionCallbacks and OnConnectionFailedListener.
4) My onConnectionFailed() method looks like:
public void onConnectionFailed(ConnectionResult result) {
//in dubug result looks like : ConnectionResult{
//statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent
// {41f8ca70: android.os.BinderProxy#41f8ca10}}
try {
if(!mIntentInProgress && result.hasResolution())
{
mIntentInProgress=true;
result.startResolutionForResult(mActivity, RC_SIGN_IN);
}
} catch (SendIntentException e) {
e.printStackTrace();
}
}
5) My onActivityResult() method contains:
if (requestCode == RC_SIGN_IN) {
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
When I run my app I get a Toast that says that an internal error popped up. I did create the project in the Google console.
I had the same problem.
From documentation:
The client may choose to continue without using the API or it may call startResolutionForResult(Activity, int) to prompt the user to sign in.
So you should try to sign in by using startResolutionForResult() function
#Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
// !!!
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}
Just follow google's instructionss
AND CAUTION
Since you are still in development mode, check if you have added your testing email address in the GAME DETAILS center before publishing the game.
Check that you are signing the app with a keystore that is in the apk uploaded to Google Play Developer's Console (if testing, you can upload as alpha and publish while keeping it private).
If not this, it could be other things. Make sure your account's email address is listed in testers in the Account details page (on the settings menu with a gear icon), and the licensed response is set to LICENSED, NOT to RESPOND_NORMALLY
This error indicates that the user needs to authorize your app. There's a full workflow for this, following the tutorial at https://developers.google.com/+/mobile/android/getting-started look for "onConnectionFailed"
Drive api should be enabled from the console page.
Not sure if this is the best answer but it worked for me. I copied onConnectionFailed() from the BasicSamples TakeANumber MainActivity. It calls BaseGameUtils to resolve. Of course that implies you have the BaseGameUtils library included in your project and that's another can of worms. But maybe you can get by with the one method so I copied it below.
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
logger.info( "onConnectionFailed() *play* : attempting to resolve");
if (mResolvingConnectionFailure) {
logger.info( "onConnectionFailed(): already resolving");
return;
}
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
}
From Google BasicSamples BaseGameUtils.java:
public static boolean resolveConnectionFailure(Activity activity,
GoogleApiClient client, ConnectionResult result, int requestCode,
String fallbackErrorMessage) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(activity, requestCode);
return true;
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
client.connect();
return false;
}
} else {
// not resolvable... so show an error message
int errorCode = result.getErrorCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
activity, requestCode);
if (dialog != null) {
dialog.show();
} else {
// no built-in dialog: show the fallback error message
showAlert(activity, fallbackErrorMessage);
}
return false;
}
}
if you are not using debug keys, push app to google play as alpha, add yourself as a tester and MOST important - follow the "Opt-in" link on Aplha page and CONFIRM that you are the tester.
I'd like to share my experience with this. My case was when using Google Play Services for Google Play Games. I was also getting the onConnectionFailed giving SIGN_IN_REQUIRED error. Finally I realize I had not "Published" my Game settings in the developer console. Not to be mistaken for publishing an "alpha" or "beta" version of your apk. I mean the actual Google Play Games "Game" you create and link to the game's APK.
I had Same problem and solved with this solution ,
I actually had very old version google play-services library so I updated It with latest google play-service library to compile 'com.google.android.gms:play-services:11.0.4' from my previous version library to support your android SDK and maintain compileSDKVersion and targetSDKVersion in gradle:app.
add google drive enabled API_KEY in manifest.and try again
In my case the problem was in sensitive scopes added and not verified:
https://console.developers.google.com/apis/credentials
Credentials -> OAuth consent screen -> Scopes for Google APIs
Make sure you have no unverified scopes.
for my cause i wrongly used release SHA1 key to generate API in developer console.
Then created SHA1 key with debug.keystore and updated in my api credentials.
Its started working.
keytool -list -v -keystore "C:\Users\<user>n\.android\debug.keystore" -alias androiddebugkey -storepass andro
id -keypass android

Categories

Resources