Class Player
Contains functions and properties related to the current player.
Inherited Members
Namespace: Meta.InstantGames
Assembly: Unity.Meta.InstantGames.Sdk.dll
Syntax
public class Player : JsObject
Constructors
Player()
Construct an instance of Player
Declaration
public Player()
Methods
CanSubscribeBotAsync()
Returns a promise that resolves with whether the player can subscribe to the game bot or not. Exceptions: RATE_LIMITED, CLIENT_UNSUPPORTED_OPERATION, INVALID_OPERATION
Declaration
public WebTask<bool> CanSubscribeBotAsync()
Returns
| Type | Description |
|---|---|
| WebTask<bool> | A WebTask<T> indicating whether a player can subscribe to the game bot or not. Developer can only call subscribeBotAsync() after checking canSubscribeBotAsync(), and the game will only be able to show the player their bot subscription dialog once per week. |
FlushDataAsync()
Immediately saves any changes to the player data to the designated cloud storage. This function is resource-intensive and should be used for critical changes where the save must be immediate. For non-critical changes, rely on the platform to save them in the background.
Note: Calls to Player.SetDataAsync will be rejected while this function's result is pending.
Declaration
public WebTask FlushDataAsync()
Returns
| Type | Description |
|---|---|
| WebTask | A WebTask that resolves when changes save successfully, and rejects if the save fails. |
GetASIDAsync()
A unique identifier for the player. This is the standard Facebook Application-Scoped ID which is used for all Graph API calls. If your game shares an AppID with a native game this is the ID you will see in the native game too.
Declaration
public WebTask<string> GetASIDAsync()
Returns
| Type | Description |
|---|---|
| WebTask<string> | A unique identifier for the player. |
GetConnectedPlayersAsync()
Fetches an array of ConnectedPlayer objects containing information about active players (people who played the game in the last 90 days) that are connected to the current player.Exceptions: NETWORK_FAILURE, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask<ConnectedPlayer[]> GetConnectedPlayersAsync()
Returns
| Type | Description |
|---|---|
| WebTask<ConnectedPlayer[]> | A WebTask<T> that resolves with a list of ConnectedPlayer. NOTE: This function should not be called until FBInstant.initializeAsync() has resolved. |
GetDataAsync(string[])
Retrieve data from the designated cloud storage of the current player. Please note that JSON objects stored as string values would be returned back as JSON objects. Returns a promise that resolves with an object which contains the current key-value pairs for each key specified in the input array, if they exist. Exceptions: INVALID_PARAM, NETWORK_FAILURE, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask<string> GetDataAsync(string[] keys)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | keys | An array of unique keys to retrieve data for |
Returns
| Type | Description |
|---|---|
| WebTask<string> | A WebTask<T> that resolves with an object, serialized as a JSON string, which contains the current key-value pairs for each key specified in the input array, if they exist. |
GetID()
A unique identifier for the player. A Facebook user's player ID will remain constant for a game, and is scoped to a specific game. This means that different games will have different player IDs for the same user. This function should not be called until FBInstant.initializeAsync() has resolved.
Declaration
public string GetID()
Returns
| Type | Description |
|---|---|
| string | A unique identifier for the player. |
GetName()
The player's localized display name. This function should not be called until FBInstant.initializeAsync() has resolved.
Declaration
public string GetName()
Returns
| Type | Description |
|---|---|
| string | The player's display name. |
GetPhoto()
A url to the player's public profile photo. The photo will always be a square, and with dimensions of at least 200x200. When rendering it in the game, the exact dimensions should never be assumed to be constant. It's recommended to always scale the image to a desired size before rendering. The value will always be null until FBInstant.initializeAsync() resolves. WARNING: Due to CORS, using these photos in the game canvas can cause it to be tainted, which will prevent the canvas data from being extracted. To prevent this, set the cross-origin attribute of the images you use to 'anonymous'.
Declaration
public string GetPhoto()
Returns
| Type | Description |
|---|---|
| string | A url to the player's public profile photo. |
GetSignedASIDAsync()
Fetch the player's Application-Scoped ID along with a signature that verifies that the identifier indeed comes from Facebook without being tampered with. This function should not be called until FBInstant.initializeAsync() has resolved.
Declaration
public WebTask<SignedASID> GetSignedASIDAsync()
Returns
| Type | Description |
|---|---|
| WebTask<SignedASID> | A WebTask<T> that resolves with a SignedASID object. |
GetSignedPlayerInfoAsync()
Fetch the player's unique identifier along with a signature that verifies that the identifier indeed comes from Facebook without being tampered with. This function should not be called until FBInstant.initializeAsync() has resolved.Exceptions: NETWORK_FAILURE, CLIENT_UNSUPPORTED_OPERATION, INVALID_PARAM
Declaration
public WebTask<SignedPlayerInfo> GetSignedPlayerInfoAsync()
Returns
| Type | Description |
|---|---|
| WebTask<SignedPlayerInfo> | A WebTask<T> that resolves with a SignedPlayerInfo object. |
SetDataAsync(string)
Set data to be saved to the designated cloud storage of the current player. The game can store up to 1MB of data for each unique player.Exceptions: INVALID_PARAM, NETWORK_FAILURE, PENDING_REQUEST, CLIENT_UNSUPPORTED_OPERATION
Declaration
public WebTask SetDataAsync(string data)
Parameters
| Type | Name | Description |
|---|---|---|
| string | data | An object containing a set of key-value pairs that should be persisted to cloud storage. The object must contain only serializable values - any non-serializable values will cause the entire modification to be rejected. |
Returns
| Type | Description |
|---|---|
| WebTask | A WebTask that resolves when the input values are set. NOTE: The promise resolving does not necessarily mean that the input has already been persisted. Rather, it means that the data was valid and has been scheduled to be saved. It also guarantees that all values that were set are now available in player.getDataAsync. |
SubscribeBotAsync()
Request that the player subscribe the bot associated to the game. The API will reject if the subscription fails - else, the player will subscribe the game bot. Exceptions: INVALID_PARAM, CLIENT_REQUIRES_UPDATE, PENDING_REQUEST
Declaration
public WebTask SubscribeBotAsync()
Returns
| Type | Description |
|---|---|
| WebTask | A WebTask that resolves if player successfully subscribed to the game bot, or rejects if request failed or player chose to not subscribe. |