question

Never Rage Dungeons and Dragons avatar image
Never Rage Dungeons and Dragons asked

GetUserData Request NodeJs

I am trying but I dont know how to get user data with Nodejs.

Any help is greatly appreciated

Hello again, I am trying to make a web app with Nodejs and playfab where player can go and sign in and get thier leaderboard stats and send friend request or play mini games. I am unable to get user data...it keep saying null

Player Data
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Hi @Never Rage Dungeons and Dragons,

I used the following code to test and it worked fine, the user data returned properly, you can have a look:

var PlayFab = require("./node_modules/playfab-sdk/Scripts/PlayFab/PlayFab");
var PlayFabClient = require("./node_modules/playfab-sdk/Scripts/PlayFab/PlayFabClient");


function Example() {
    PlayFab.settings.titleId = "your title id";
    var loginRequest = {
        // Currently, you need to look up the correct format for this object in the API reference for LoginWithCustomID.
        TitleId: PlayFab.settings.titleId,
        CustomId: "your player's custom id",  
        CreateAccount: false
    };


    PlayFabClient.LoginWithCustomID(loginRequest, LoginCallback);
}


function LoginCallback(error, result) {
    if (result !== null) {
        console.log("Now Get User Data:");
        var getUserDataRequest ={
           Keys: ["name of the key(s) stored for the player"]
        };


        PlayFabClient.GetUserData(getUserDataRequest,GetUserDataCallback);




    } else if (error !== null) {
        console.log("Something went wrong with your first API call.");
        console.log("Here's some debug information:");
        console.log(CompileErrorReport(error));
    }
}


function GetUserDataCallback(error, result){
    if (result !== null) {
        console.log("The response is: "+ JSON.stringify(result));


    } else if (error !== null) {
        console.log("Something went wrong with your first API call.");
        console.log("Here's some debug information:");
        console.log(CompileErrorReport(error));
    }
}


// This is a utility function we haven't put into the core SDK yet. Feel free to use it.
function CompileErrorReport(error) {
    if (error == null)
        return "";
    var fullErrors = error.errorMessage;
    for (var paramName in error.errorDetails)
        for (var msgIdx in error.errorDetails[paramName])
            fullErrors += "\n" + paramName + ": " + error.errorDetails[paramName][msgIdx];
    return fullErrors;
}


// Kick off the acutla login call
Example();
1 comment
10 |1200

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

Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons commented ·

Thank you Sir

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

First of all, which API did you use to get the user data, is it Server/GetUserData, Client/GetUserData, or Admin/GetUserData? Can you share more details (for instance, request body) about the GetUserData Request you made to PlayFab?

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.

Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons commented ·

function GetUserData(){ var getdataRequest = PlayFabClient.GetUserData({ PlayFabId: playerId, Keys: ["Test"], });

0 Likes 0 ·
Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons commented ·

I gived up trying to log the value with console because it keeps saying null...I know by default the string value is set to null, but I was able to update the key with a value....Can you show me how you would do it...at this point I just need an example script cause the Documentation only has it for Unity Engine which is different.

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.