Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by andreighinea1 · Oct 01, 2018 at 05:21 PM · Player Datadata

GetServerAuthCode() from google login is always empty

I'm trying to save player data to a playfab account created from a google login. The google login process appears to be working almost ok, I can see my achievements and the login icon, but when I try to get the ServerAuthCode it's always empty.

This is my current code:

public class Achievements : MonoBehaviour {
    public PlayFabLogin PlayFabLogin;
#if UNITY_ANDROID
    PlayGamesClientConfiguration config;
#endif


#if UNITY_ANDROID || UNITY_IOS
    void Start ()
    {
#if UNITY_ANDROID
        if (PlayGamesPlatform.Instance.localUser.authenticated)
            return;
        config = new PlayGamesClientConfiguration.Builder()
            /*.AddOauthScope("profile")
            .AddOauthScope("email")
            .RequestIdToken()*/
            .RequestServerAuthCode(false)
            .Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
        PlayGamesPlatform.Instance.SignOut();
#elif UNITY_IOS
        if (Social.localUser.authenticated)
            return;
#endif
        SignIn();
    }
#endif


    void SignIn()
    {
#if UNITY_ANDROID || UNITY_IOS
        Social.localUser.Authenticate((bool success, string error) => {
            if (success)
            {
#if UNITY_ANDROID
                StartCoroutine(PlayFabLogin.LoginGoogle(config));
#endif
            }
            else
            {
                Debug.LogError("Login-Google login failed: " + error);
            }
        });
#endif
    }
}




And the PlayfabLogin class:
public class PlayFabLogin : MonoBehaviour
{
    public InputField EmailInputField, UsernameInputField, PasswordInputField;


#if !DISABLESTEAMWORKS
    LoginWithSteamRequest request;
#elif UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX
    LoginWithGameCenterRequest request;
#elif UNITY_XBOXONE
    //LoginWithXboxRequest request;
#endif


    public void Start()
    {
#if !DISABLESTEAMWORKS
        request = new LoginWithSteamRequest();
        PlayFabClientAPI.LoginWithSteam(request, OnLoginSuccess, OnLoginFailure);
#elif UNITY_ANDROID
        //LoginGoogle();
#elif UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX
        request = new LoginWithGameCenterRequest();
        request.CreateAccount = true;
        PlayFabClientAPI.LoginWithGameCenter(request, OnLoginSuccess, OnLoginFailure);
#elif UNITY_XBOXONE
        request = new LoginWithXboxRequest();
        request.CreateAccount = true;
        PlayFabClientAPI.LoginWithXbox(request, OnLoginSuccess, OnLoginFailure);
#endif
    }


#if UNITY_ANDROID
    public IEnumerator LoginGoogle(PlayGamesClientConfiguration config)
    {
        yield return new WaitForSecondsRealtime(5);
        string serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();


        Debug.Log("Login-LoginGoogle-Login with serverAuthCode: " + serverAuthCode);
        LoginWithGoogleAccountRequest request;
        request = new LoginWithGoogleAccountRequest()
        {
            TitleId = PlayFabSettings.TitleId,
            CreateAccount = true,
            ServerAuthCode = serverAuthCode
        };
    }
#endif




    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("Congratulations, you made your first successful API call!\n Signed In as" + result.PlayFabId);
    }


    private void OnLoginFailure(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your first API call.  :(");
        Debug.LogError("Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }
}

asd

Comment

People who like this

0 Show 0
10 |1200 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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Andy · Oct 01, 2018 at 05:54 PM

That's not really a PlayFab issue, but an issue with the Google Play API for Unity. I did a quick search and found this open issue: https://github.com/playgameservices/play-games-plugin-for-unity/issues/2053. If you scroll down a bit, it looks like someone has proposed a work around. Good Luck!

Comment

People who like this

0 Show 0 · Share
10 |1200 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.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    I have an existing Java backend with user data stored in MYSQL, want to move that data to PlayFab. 1 Answer

    Uploading A File To Playfab 1 Answer

    How to get other players public [player data] with client API? 1 Answer

    Why suggest to use Player Statistics for keep Plater Xp? 1 Answer

    Can I export all Player and Character data (e.g. Inventory, Virtual Currency, etc) 2 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges