App is crashing while using play games services in unity project - android

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

Related

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

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 !

Xamarin Google SignIn for Android - Refresh and Access Tokens

Using VisualStudio, I recently successfully implemented client-flow authentication for my Xamarin.Forms app via the Xamarin.Google.iOS.SignIn NuGet package. This sign-in is then used to allow the app access to our server API components via Azure Mobile Services MobileServicesClient.
It hinges on the ability to pass to Azure the access_token, refresh_token, and id_token from the Google IDP API - all 3 of which are available nicely after a sign in as SignIn.SharedInstance.CurrentUser.Authentication.AccessToken, SignIn.SharedInstance.CurrentUser.Authentication.RefreshToken and SignIn.SharedInstance.CurrentUser.Authentication.IdToken.
I am now trying to implement similar behavior in the Android version of our Xamarin.Forms app using the Xamarin.GooglePlayServices.Auth NuGet package.
However, although I think I have the basics in place for getting a successful authentication with Google, I cannot see how to retrieve the tokens I need from the result.
The google documentation talks about enabling retrieval of the IDToken and ServerAuthCode via setting up the GoogleSignInOptions object before building the APIClient, but not how to get the refresh_ or access_token from google? It seems to want to lay this responsibility onto our sever API. That is not how our iOS app works. Anyone successfully done this in an app using this NuGet package API? Does the Xamarin Android Google SignIn API even support what I want to do?
Yes, this is possible, try something like the following (disregarding where we see App.PostLoginAction - that is specific to my app, although certainly you can take a similar approach and implement an action at the App level as I have done to catch the results).
public class GoogleLoginService : Java.Lang.Object, GoogleApiClient.IConnectionCallbacks, GoogleApiClient.IOnConnectionFailedListener
{
public static GoogleApiClient GoogleApiClient { get; set; }
public static GoogleLoginService Instance { get; private set; }
public GoogleLoginService()
{
Instance = this;
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestIdToken("YourAppsWebClientId") //note this is the WEB client id, NOT the android app client id
.RequestEmail()
.Build();
GoogleApiClient = new GoogleApiClient.Builder(CrossCurrentActivity.Current.Activity) //note you need to install the plugin king's (James Montemagno) Plugin.CurrentActivity nuget for this
.AddConnectionCallbacks(this)
.AddOnConnectionFailedListener(this)
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
.AddScope(new Scope(Scopes.Email))
.AddScope(new Scope(Scopes.Profile))
.Build();
}
public void Login()
{
Intent signInIntent = Auth.GoogleSignInApi.GetSignInIntent(GoogleApiClient);
CrossCurrentActivity.Current.Activity.StartActivityForResult(signInIntent, 1);
GoogleApiClient.Connect();
}
public void Logout()
{
GoogleApiClient.Disconnect();
}
public void OnAuthCompleted(GoogleSignInResult result)
{
if (result.IsSuccess)
{
Task.Factory.StartNew(()=> {
//note result.SignInAccount.IdToken is NOT the access token, so we need this:
var accessToken = GoogleAuthUtil.GetToken(Android.App.Application.Context, result.SignInAccount.Account, $"oauth2:{Scopes.Email} {Scopes.Profile}");
App.PostLoginAction(SocialProvider.Google, accessToken , "Success!");
});
//to get user profile directly, without having to make separate call using the access token:
GoogleSignInAccount account = result.SignInAccount; //contains stuff like name, email, pic url, gender
}
else
{
App.PostLoginAction(SocialProvider.Google, null, "An error occurred.");
}
}
public void OnConnected(Bundle connectionHint)
{
}
public void OnConnectionSuspended(int cause)
{
App.PostLoginAction(SocialProvider.Google, null, "Canceled!");
}
public void OnConnectionFailed(ConnectionResult result)
{
App.PostLoginAction(SocialProvider.Google, null, $"An error occurred: {result.ErrorMessage}");
}
}

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

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...

Google Play services integration fails with Cocos2d-x

I'm using latest Google Play services v4323030, downloaded BaseUtility library from GIT as written in google developer documentation.
In project using only GameHelper and GameHelperUtils classes without BaseGameActivity.
Initializing GameHelper in OnCreate method:
mHandler.postDelayed(new Runnable()
{
#Override
public void run()
{
if (!isGameCenterDisabled())
{
gameHelper = new GameHelper(Cocos2dxActivity.this,GameHelper.CLIENT_ALL);
GameHelperListener listener = new GameHelper.GameHelperListener() {
#Override
public void onSignInSucceeded() {
// handle sign-in succeess
}
#Override
public void onSignInFailed() {
// handle sign-in failure (e.g. show Sign In button)
}
};
gameHelper.setup(listener);
gameHelper.onStart(Cocos2dxActivity.this);
}
}
}, 3000);
Game is started and then it crashing:
Interface method not part of interface class
Could not find method com.google.android.gms.common.api.GoogleApiClient.isConnected, referenced from method com.google.example.games.basegameutils.GameHelper.getRequests
unable to resolve interface method 12116: Lcom/google/android/gms/common/api/GoogleApiClient;.isConnected ()Z
Cannot understand where can be trouble, why this methods is not visible...
Found out that during previous google play services update something gonna wrong, deleted and reinstalled then found out that current version is 4323000, modified manifest file to pick this version and everything looks works now.

Categories

Resources