question

Unnamed Studio avatar image
Unnamed Studio asked

Trouble with Getting Started instructions

I'm using Unity.

I'm followed the "Getting Started" post here
https://api.playfab.com/docs/getting-started-with-playfab

I made an empty game object and attached the script to it.
I get these errors:

Error #1

Error logging in player with custom ID:
UnityEngine.Debug:Log(Object)
PlayFabManager:<Login>m__1(PlayFabError) (at Assets/PlayFabManager.cs:33)
PlayFab.<LoginWithCustomID>c__AnonStorey2A:<>m__4E(String, PlayFabError) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:195)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:249)

Error #2

Couldn't resolve host '.playfabapi.com'
UnityEngine.Debug:Log(Object)
PlayFabManager:<Login>m__1(PlayFabError) (at Assets/PlayFabManager.cs:34)
PlayFab.<LoginWithCustomID>c__AnonStorey2A:<>m__4E(String, PlayFabError) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:195)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:249)

My Code: (I substituted my GameTitleId with "XXXX" for this post)

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

public class PlayFabManager : MonoBehaviour {

    public string PlayFabId;

    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)");
            }
        },
        (error) => {
            Debug.Log("Error logging in player with custom ID:");
            Debug.Log(error.ErrorMessage);
        });
    }

    // Use this for initialization
    void Start () {
        Login ("XXXX");
    }

    // Update is called once per frame
    void Update () {

    }
}

Please advise what I'm doing wrong or if this is supposed to be the result. I thought it's supposed to create a new player account and return a newly generated PlayFabId?

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

Error #2 clearly shows that the TitleId is not set otherwise you should get:
{ {TitleId}}.playfabapi.com instead of '.playfabapi.com'.
TitleId should be set from any MonoBehaviour as follows:

    using PlayFab;

    void Awake(){
        PlayFabSettings.TitleId = "AD08"; //your title id goes here.
    }

Please follow UnitySDK github repository README.

10 |1200

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

Unnamed Studio avatar image
Unnamed Studio answered

Thank you Hamza! :-)

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

My pleasure!

10 |1200

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

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.