Players Data
Get Player Data
+1 RequestYou can access other players' data, including achievements and purchases.
All fields marked public will be available to other players.
- JavaScript
- Unity
const result = await gp.players.fetch({
// Search by player ID
ids: [66506, 66254],
});
// Response
const { players } = result;
// Player state
players[0].state
// Examples
players[0].state.id
players[0].state.name
players[0].state.score
players[0].state.gold
// Player achievements, see Achievements section
players[0].achievements
// Examples
players[0].achievements[0].id
players[0].achievements[0].createdAt
// Player purchases, see Payments section
players[0].purchases
// Examples
players[0].purchases[0].id
players[0].purchases[0].createdAt
private void FetchPlayers(List<int> playersId)
{
GP_Players.Fetch(playersId, OnPlayersFetchSuccess, OnPlayersFetchError);
}
// Fetch response
private void OnPlayersFetchSuccess(GP_Data data)
{
var players = data.GetList<PlayersData>();
for (int i = 0; i < players.Count; i++)
{
Debug.Log("PLAYER STATE: AVATAR " + players[i].state.avatar);
Debug.Log("PLAYER STATE: CREDITIALS " + players[i].state.credentials);
Debug.Log("PLAYER STATE: ID " + players[i].state.id);
Debug.Log("PLAYER STATE: NAME " + players[i].state.name);
Debug.Log("PLAYER STATE: PLATFORM TYPE " + players[i].state.platformType);
Debug.Log("PLAYER STATE: PROJECT ID " + players[i].state.projectId);
Debug.Log("PLAYER STATE: SCORE " + players[i].state.score);
// Player achievements, see Achievements section
for (int a = 0; a < players[i].achievements.Length; a++)
{
Debug.Log("PLAYER ACHIEVEMENTS: ID " + players[i].achievements[a].id);
Debug.Log("PLAYER ACHIEVEMENTS: TAG " + players[i].achievements[a].tag);
Debug.Log("PLAYER ACHIEVEMENTS: CREATED AT " + players[i].achievements[a].createdAt);
}
// Player purchases, see Payments section
for (int x = 0; x < players[i].purchasesList.Length; x++)
{
Debug.Log("PLAYER PURCHASES: CREATED AT " + players[i].purchasesList[x].createdAt);
Debug.Log("PLAYER PURCHASES: EXPIRED AT " + players[i].purchasesList[x].expiredAt);
Debug.Log("PLAYER PURCHASES: GIFT " + players[i].purchasesList[x].gift);
Debug.Log("PLAYER PURCHASES: PRODUCT ID " + players[i].purchasesList[x].productId);
Debug.Log("PLAYER PURCHASES: SUBSCRIBED " + players[i].purchasesList[x].subscribed);
Debug.Log("PLAYER PURCHASES: TAG " + players[i].purchasesList[x].tag);
}
}
}
//On fetch error
private void OnPlayersFetchError() => Debug.Log("PLAYERS FETCH: ERROR");
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!