question

plazmainteractive avatar image
plazmainteractive asked

New user here. Having trouble logging in to Kongregate.

Hello guys. I've recently started to use PlayFab in hopes that I may be able to store player's game data so the next time they come back to the game, they can start where they left last time. As this is also the first time I used a backend service, the whole thing is a bit confusing to me.

Here's what I'm trying to achieve:

1. Connect to Kongregate API then login to PlayFab based on user info

2. Automatically start checking if the user is a newly created account or an existing one. If it's a newly created account, make a new player on Game Manager and add the initial data for them. If it's an existing user, start loading their saved data and use them in the game.

I did the first step with an early build and it worked. PlayFab created my Kongregate account on the Players tab with the correct informations. So I went ahead and tried the save/load step and came across a problem when I test my build out. This error come up in a text I set up in Unity:

"Error logging in player with custom ID: Unknown Error."

To give a bit more informations out, my early build consist of the two scripts below. The difference is, my PlayFabManager doesn't have both the SaveUserData() and LoadUserData() method and the condition check that I added inside the Login() method. My current build basically has the same exact scripts that I provided below. I also tried deleting the user using the Try It button in the docs but it doesn't solve anything.

Here's the PlayFabManager code:

using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;


public class PlayFabManager : MonoBehaviour
{
    public static PlayFabManager instance;
    public string playFabID;
    public string titleID;


    public List<string> items;


    public Text playfabConnection;
    public Text playfabStatus;
    public Text userDataString;


    void Awake()
    {
        instance = this;
    }


    public void Login(string kongregateID, string authTicket)
    {
        LoginWithKongregateRequest request = new LoginWithKongregateRequest()
        {
            TitleId = titleID,
            // UserID
            KongregateId = kongregateID,
            // GameAuthToken
            AuthTicket = authTicket,
            CreateAccount = true,
        };


        PlayFabClientAPI.LoginWithKongregate(request, (result) =>
        {
            // Get unique PlayFab ID
            playFabID = result.PlayFabId;
            // Connected
            playfabConnection.text = "Got PlayFabID: " + playFabID;


            if (result.NewlyCreated)
            {
                // If new account
                playfabStatus.text = "(new account)";
            }
            else
            {
                // If existing account
                playfabStatus.text = "(existing account)";
            }
        },
        (error) =>
        {
            // Error message
            playfabStatus.text = string.Format("Error logging in player with custom ID:\n{0}", error.ErrorMessage);
        });
    }


    public void SaveUserData()
    {
        UpdateUserDataRequest request = new UpdateUserDataRequest()
        {
            Data = new Dictionary<string, string>
            {
                // Save score to Score key
                { "Score", GameManager.instance.score.ToString() }
            }
        };


        PlayFabClientAPI.UpdateUserData(request, (result) =>
        {
            Debug.Log("Successfully updated user data");
        },
        (error) =>
        {
            // Error message
            Debug.Log(error.ErrorDetails);
        });
    }


    public void LoadUserData()
    {
        GetUserDataRequest request = new GetUserDataRequest()
        {
            PlayFabId = playFabID,
            // Get all data
            Keys = null,
        };


        PlayFabClientAPI.GetUserData(request, (result) =>
        {
            // Got data
            Debug.Log("Got user data");
            if (result == null || result.Data.Count == 0)
            {
                // No data available
                Debug.Log("No user data available");
            }
            else
            {
                // Clear list first
                items.Clear();
                foreach (var item in result.Data)
                {
                    // Retrieve user item and add to list
                    string userItem = string.Format(item.Key + ":" + item.Value.Value);
                    items.Add(userItem);
                }
                // Add the list of item together as one string to be used later
                userDataString.text = string.Join("|", items.ToArray());
            }
        },
        (error) =>
        {
            // Error message
            Debug.Log(error.ErrorMessage);
        });
    }
}

Here's the KongregateAPI code:

using UnityEngine;
using UnityEngine.UI;


public class KongregateAPI : MonoBehaviour
{
    public static KongregateAPI instance;


    public int userID;
    public string username;
    public string gameAuthToken;


    public Text connectText;


    void Awake()
    {
        instance = this;


        Application.ExternalEval(
        @"if(typeof(kongregateUnitySupport) != 'undefined'){
        kongregateUnitySupport.initAPI('KongregateAPI', 'OnKongregateAPILoaded');
        };");
    }


    public void OnKongregateAPILoaded(string userInfoString)
    {
        OnKongregateUserInfo(userInfoString);


        // Login when Kongregate is connected
        PlayFabManager.instance.Login(userID.ToString(), gameAuthToken);
    }


    public void OnKongregateUserInfo(string userInfoString)
    {
        var info = userInfoString.Split('|');
        userID = System.Convert.ToInt32(info[0]);
        username = info[1];
        gameAuthToken = info[2];
        // Display the user informations in a text
        connectText.text = string.Format("UserID: {0}\nUsername: {1}\nToken: {2}", userID, username, gameAuthToken);
    }


    public static void SubmitStat(string statName, int statValue)
    {
        Application.ExternalCall("kongregate.stats.submit", statName, statValue);
    }
}

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

·
brendan avatar image
brendan answered

Okay, the first thing to note is that you're attempting to log in using LoginWithKongregate. Your error handling code for that call is where the "Error logging in player with custom ID" message comes from. And so the actual message that's tagged to that ("Unknown Error") is coming from Kongregate in this case. We can still help to track this down, though - what are the specific values you're passing into the LoginWithKongregate call?

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

plazmainteractive avatar image plazmainteractive commented ·

The specific values as in you want me to tell the userID and gameAuthToken values Kongregate gives to me right? If that's the case here is what I gathered:

TitleId = 842C

KongregateId = 29683077 (userID of my Kongregate account)

Not sure about AuthTicket though. Retrieving the gameAuthToken from the KongregateAPI comes up empty but regardless, I'm able to login in my previous build.

0 Likes 0 ·
brendan avatar image brendan plazmainteractive commented ·

I'm afraid I don't follow. If the gameAuthToken you get back from Kongregate is an empty string, there's no way the LoginWithKongregate call would work, since we're not able to provide that service with anything to indicate who the user is. Can you step into this in your debugger and see what the token looks like when you're calling LoginWithKongregate?

0 Likes 0 ·
plazmainteractive avatar image plazmainteractive commented ·

Sorry for the inconvenience. I realized Kongregate did return a gameAuthToken and as I was relying on a text box I created, the gameAuthToken string was hidden because I ran out of space on that text box. With that out of the way, here's the gameAuthToken string:

e3ddd854241467b931e9633b181deb8605001a4f833b77f9c6365c02000d0979

0 Likes 0 ·
brendan avatar image brendan plazmainteractive commented ·

I've been reviewing the logs and code, and I'm not seeing a valid way for "Unknown Error" to be returned. Can you put a breakpoint into your code there, and let me know what the rest of the PlayFab error response contains - particularly the errorDetails? Also, can you check that other login methods work for you in your test code, like LoginWithCustomID?

0 Likes 0 ·

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.