question

Kim Strasser avatar image
Kim Strasser asked

Issue with FirstLogin in Cloud Script

I get this JavascriptException when I want to get the players FirstLogin in Cloud Script:

 "Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "TypeError: Cannot read property 'UserInfo' of undefined\n    at handlers.GetFirstLoginDate (BFD0A-main.js:600:49)\n    at Object.invokeFunction (Script:116:33)"
        }
sessionticketcreationdate = result.data.UserInfo.TitleInfo.FirstLogin;

In Postman, the API AuthenticateSessionTicket has this response structure: data-->UserInfo-->TitleInfo-->FirstLogin

{
    "code": 200,
    "status": "OK",
    "data": {
        "UserInfo": {
            "PlayFabId": "8882308D85826F31",
            "Created": "2019-12-22T08:22:30.749Z",
            "Username": "postmanuser",
            "TitleInfo": {
                "DisplayName": "PostmanDisplayname",
                "Origination": "Organic",
                "Created": "2019-12-22T08:22:30.937Z",
                "LastLogin": "2019-12-29T16:44:37.294Z",
                "FirstLogin": "2019-12-22T08:22:30.937Z",
                "isBanned": false,
                "TitlePlayerAccount": {
                    "Id": "7BBDEEBC993F528B",
                    "Type": "title_player_account",
                    "TypeString": "title_player_account"
                }
            },
            "PrivateInfo": {
                "Email": "postmanemail@test.com"
            }
        }
    }
}

I thought that I can use the same structure in my Cloud Script if I want to get FirstLogin.

Why am I getting a JavascriptException when I use result.data.UserInfo.TitleInfo.FirstLogin ?

Cloud Script:

handlers.GetFirstLoginDate = function (args, context)
{
    var result = server.AuthenticateSessionTicket(
    {
        SessionTicket: args.Sessionticket
    });
       
    var sessionticketcreationdate = "";
    if (result.Error == null)
    {
        sessionticketcreationdate = result.data.UserInfo.TitleInfo.FirstLogin;
    }
    else
        sessionticketcreationdate = "Could not get First Login date."

    return sessionticketcreationdate;
}
CloudScript
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

·
Sarah Zhang avatar image
Sarah Zhang answered

You can refer to the following code, please remove the "data.".

handlers.GetFirstLoginDate = function (args, context)
{
    var result = server.AuthenticateSessionTicket(
    {
        SessionTicket: args.Sessionticket
    });
       
    var sessionticketcreationdate = "";
    if (result.Error == null)
    {
        sessionticketcreationdate = result.UserInfo.TitleInfo.FirstLogin;
    }
    else
        sessionticketcreationdate = "Could not get First Login date."
 
    return sessionticketcreationdate;
}
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.