question

fluxsidestudios avatar image
fluxsidestudios asked

Login Problems (My code not login servers)

Hello, I am having trouble getting my playfab login code to work. We are currently only published to Android so I only need to worry about it and not iOS login or any other platform. I had it working before with the regular systemDeviceIdentifer instead of the Android specific ID but once I switch it to the android id it stopped working. I'm using the Unity Editor extension for the playfab id. Here's my code below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


using PlayFab;
using PlayFab.ClientModels;


public class PlayFabManager : MonoBehaviour
{
    public string PlayFabId;


    void Start()
    {
		if (Application.platform == RuntimePlatform.Android) {
			AndroidLogin (PlayFabSettings.TitleId);
		} else {
			Login (PlayFabSettings.TitleId);
		}


        DontDestroyOnLoad(this);
    }


    void Login(string titleId)
    {
        LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
        {
            TitleId = titleId,
            CreateAccount = true,
            CustomId = SystemInfo.deviceUniqueIdentifier
        };


        PlayFabClientAPI.LoginWithCustomID(request, (result) => {
            PlayFabId = result.PlayFabId;
            Debug.Log("Got PlayFabID: " + PlayFabId);


            if (result.NewlyCreated)
            {
                Debug.Log("(new account)");
            }
            else
            {
                Debug.Log("(existing account)");
            }


            PlayFabId = result.PlayFabId;
        },
            (error) => {
                Debug.Log("Error logging in player with custom ID:");
            });
    }


    void AndroidLogin(string titleId)
    {
		AndroidJavaClass up = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
		AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject> ("currentActivity");
		AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject> ("getContentResolver");  
		AndroidJavaClass secure = new AndroidJavaClass ("android.provider.Settings$Secure");
		string android_id = secure.CallStatic<string> ("getString", contentResolver, "android_id");


        LoginWithAndroidDeviceIDRequest request = new LoginWithAndroidDeviceIDRequest()
        {
            TitleId = titleId,
            CreateAccount = true,
			AndroidDeviceId = android_id
        };


        PlayFabClientAPI.LoginWithAndroidDeviceID(request, (result) => {
            PlayFabId = result.PlayFabId;
            Debug.Log("Got PlayFabID: " + PlayFabId);


            if (result.NewlyCreated)
            {
                Debug.Log("(new account)");
            }
            else
            {
                Debug.Log("(existing account)");
            }


            PlayFabId = result.PlayFabId;
        },
            (error) => {
                Debug.Log("Error logging in player with custom ID:");
            });
    }
}
sdks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
fluxsidestudios avatar image
fluxsidestudios answered

This fixed itself when I upgraded to Unity SDK 2.15 from 2.13.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Glad to hear it. For the sake of anyone running into this later, what was the specific result you were getting back from the login call?

0 Likes 0 ·
fluxsidestudios avatar image fluxsidestudios brendan commented ·

I was not getting any error (as far as I could find, I couldn't get the console output from my android device) but when I checked the dashboard there was no logins or any new player ids.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.