Facebook 遊戲開發更新文件 API參考v6.2

Facebook開發者論壇發表於2018-08-07

為方便大家群策群力,我們建立了一個 Facebook Instant Game?? 交流群: 群三638777518。 群二795963169。 群一814298516 。 歡迎同學們加入交流開發和運營經驗。

Facebook 遊戲開發更新文件 API參考v6.2

Facebook 遊戲開發更新文件 API參考v6.2

Facebook 遊戲開發更新文件 API參考v6.2

更新日誌 1.連線玩家得分條目 引入新Leaderboard.getConnectedPlayerEntriesAsync()API,從排行榜獲取當前玩家連線玩家的得分條目。

FBInstant Instant Games SDK的頂級名稱空間。

播放機 包含與當前播放器相關的功能和屬性。

getID() 播放器的唯一識別符號。Facebook使用者的玩家ID將保持不變,並且範圍限定為特定遊戲。這意味著不同的遊戲將為同一使用者提供不同的玩家ID。在FBInstant.initializeAsync()解決之前,不應呼叫此函式。 例子 //應該在FBInstant.initializeAsync()//結算後呼叫此函式。var playerID = FBInstant 。球員。getID (); 返回字串?播放器的唯一識別符號。

getSignedPlayerInfoAsync() 獲取播放器的唯一識別符號以及簽名,該簽名驗證識別符號確實來自Facebook而不會被篡改。在FBInstant.initializeAsync()解決之前,不應呼叫此函式。 引數 requestPayload 字串?開發人員指定的有效負載,包含在已簽名的響應中。 例子 //應該在FBInstant.initializeAsync()//結算後呼叫此函式。FBInstant 。球員。getSignedPlayerInfoAsync ('my_metadata' )。然後(函式(結果){ // ID和簽名的驗證應該發生在伺服器端。SendToMyServer ( 結果。getPlayerID (),//相同的值FBInstant.player.getID() 結果。getSignature (),“GAIN_COINS ' ,100 ); });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < SignedPlayerInfo >使用#signedplayerinfo物件解析的 promise。

canSubscribeBotAsync() 返回一個承諾,該承諾通過玩家是否可以訂閱遊戲機器人來解決。 例子 //應該在FBInstant.player.subscribeBotAsync()FBInstant 之前呼叫此函式。球員。canSubscribeBotAsync ()。然後( can_subscribe => 控制檯。日誌(can_subscribe )); //'真' 返回Promise < boolean >玩家是否可以訂閱遊戲機器人。開發人員只能在檢查canSubscribeBotAsync()後呼叫subscribeBotAsync(),並且播放器只能在特定遊戲中看到一次此機器人訂閱對話方塊。

subscribeBotAsync() 請求玩家訂閱與遊戲相關聯的機器人。如果訂閱失敗,API將拒絕 - 否則,玩家將訂閱遊戲機器人。 例子 FBInstant 。球員。subscribeBotAsync ()。然後(//玩家訂閱機器人)。catch (function (e ){ //處理訂閱失敗});

丟擲INVALID_PARAM 丟擲PENDING_REQUEST 引發CLIENT_REQUIRES_UPDATE 返回Promise一個承諾,如果玩家成功訂閱遊戲機器人,則解析,或者如果請求失敗或玩家選擇不訂閱則拒絕。

getName() 播放器的本地化顯示名稱。在FBInstant.startGameAsync()解析之前,不應呼叫此函式。 例子 //應該在FBInstant.startGameAsync()//結算後呼叫此函式。var playerName = FBInstant 。球員。getName (); 返回字串?播放器的本地化顯示名稱。

getPhoto() 玩家公開個人資料照片的網址。照片將始終為正方形,尺寸至少為200x200。在遊戲中渲染時,不應假設精確尺寸不變。建議在渲染之前始終將影象縮放到所需的大小。在FBInstant.startGameAsync()結算之前,該值始終為null。 警告:由於CORS,在遊戲畫布中使用這些照片會導致它被汙染,這將阻止提取畫布資料。要防止這種情況,請將您使用的影象的跨原點屬性設定為“匿名”。 例子 var playerImage = new Image (); playerImage 。crossOrigin = 'anonymous' ; //應該在FBInstant.startGameAsync()//結算後呼叫此函式。 playerImage 。src = FBInstant 。球員。getPhoto ();
返回字串?網址為玩家的公開個人資料照片。

getDataAsync() 從當前播放器的指定雲端儲存中檢索資料。 引數 keys Array < string >用於檢索資料的唯一鍵陣列。 例子 FBInstant 。球員 。getDataAsync ([ 'achievement' ,'currentLife' ])。然後(功能(資料){ 控制檯。日誌('資料載入' ); VAR 成就= 資料[ '成就' ]; VAR currentLife = 資料[ 'currentLife' ]; });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < Object >一個promise,它使用一個物件解析,該物件包含輸入陣列中指定的每個鍵的當前鍵值對(如果存在)。

setDataAsync() 將資料設定為當前播放器的指定雲端儲存。該遊戲可以為每個獨特的玩家儲存多達1MB的資料。 引數 data Object包含應保留到雲端儲存的一組鍵值對的物件。該物件必須只包含可序列化的值 - 任何不可序列化的值都將導致整個修改被拒絕。 例子 FBInstant 。球員 。setDataAsync ({ achievement :[ 'medal1' ,'medal2' ,'medal3' ], currentLife :300 ,})。然後(函式(){ 控制檯。登入('資料被設定' ); });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise在設定輸入值時解析的promise。注意:承諾解析並不一定意味著輸入已被持久化。相反,它意味著資料有效並已安排儲存。它還保證所有已設定的值現在都可以在player.getDataAsync中使用。

flushDataAsync() 立即將對播放器資料的任何更改重新整理到指定的雲端儲存。此功能很昂貴,主要應用於需要立即持久並且遊戲已知的永續性的關鍵更改。非關鍵性更改應依賴於平臺將其保留在後臺。注意:當此函式的結果處於掛起狀態時,將拒絕對player.setDataAsync的呼叫。 例子 FBInstant 。球員 。setDataAsync ({ achievement :[ 'medal1' ,'medal2' ,'medal3' ], currentLife :300 ,})。然後(FBInstant 。球員。flushDataAsync )。然後(函式(){ 控制檯。登入('資料儲存到FB!' ); });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise在成功持久儲存更改時解析的promise,如果儲存失敗則拒絕。

getStatsAsync() 從當前播放器的指定雲端儲存中檢索統計資訊。 引數 keys 陣列 < string >?用於檢索統計資訊的可選陣列唯一鍵。如果在沒有它的情況下呼叫該函式,它將獲取所有統計資訊。 例子 FBInstant 。球員 。getStatsAsync ([ 'level' ,'zombiesSlain' ])。然後(函式(統計){ 控制檯。日誌('統計被載入' ); 無功電平= 資料[ '等級' ]; VAR zombiesSlain = 資料[ 'zombiesSlain' ]; });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < Object >一個promise,它使用一個物件解析,該物件包含輸入陣列中指定的每個鍵的當前鍵值對(如果存在)。

setStatsAsync() 將統計資訊設定為當前播放器的指定雲端儲存。 引數 stats Object包含一組鍵值對的物件,這些鍵值對應作為統計資訊儲存到雲端儲存中,可以通過多種方式顯示或使用,以有益於玩家參與。物件必須只包含數值 - 任何非數值都將導致整個修改被拒絕。 例子 FBInstant 。球員 。setStatsAsync ({ level :5 , zombiesSlain :27 ,})。然後(函式(){ 控制檯。登入('資料被設定' ); });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise 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 validated and has been scheduled to be saved. It also guarantees that all values that were set are now available in player.getStatsAsync.

incrementStatsAsync( ) Increment stats saved in the designated cloud storage of the current player. Parameters increments Object An object containing a set of key-value pairs indicating how much to increment each stat in cloud storage. The object must contain only numerical values - any non-numerical values will cause the entire modification to be rejected. Examples FBInstant.player .incrementStatsAsync({ level: 1, zombiesSlain: 17, rank: -1, }) .then(function(stats)) { console.log('increments have been made! New values'); var level = data['level']; var zombiesSlain = data['zombiesSlain']; }); 丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < Object >一個promise,它使用一個物件解析,該物件包含輸入字典中指定的每個鍵的更新鍵值對。注意:承諾解決並不一定意味著更改已經保留。相反,它意味著增量有效並已安排執行。它還保證所有遞增的值現在都可以在player.getStatsAsync中使用。

getConnectedPlayersAsync() 獲取一組ConnectedPlayer物件,其中包含有關連線到當前玩家的活動玩家(在過去90天內玩過該遊戲的人)的資訊。 例子 var connectedPlayers = FBInstant 。球員。getConnectedPlayersAsync ()。然後(功能(播放器){ 控制檯。日誌(球員。地圖(功能(播放器){ 返回{ ID :玩家。的getID (), 名稱:玩家。的getName ()} })); });

// [{id:'123456789',名稱:'Paul Atreides'},{id:'987654321',名稱:'Duncan Idaho'}] 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < Array < ConnectedPlayer >>使用已連線的播放器物件列表解析的promise。注意:在FBInstant.startGameAsync()解析之前,不應呼叫此函式。

上下文 包含與當前遊戲上下文相關的功能和屬性。

getID() 當前遊戲上下文的唯一識別符號。這表示正在播放遊戲的特定上下文(例如,特定的信使對話或Facebook帖子)。如果在獨奏上下文中播放遊戲,則識別符號將為null。在FBInstant.startGameAsync解決之前,不應呼叫此函式。 例子 //應該在FBInstant.startGameAsync()//結算後呼叫此函式。var contextID = FBInstant 。背景。getID (); 返回字串?當前遊戲上下文的唯一識別符號。

getType() The type of the current game context. POST - A facebook post. THREAD - A messenger thread. GROUP - A facebook group. SOLO - Default context, where the player is the only participant. This function should not be called until FBInstant.startGameAsync has resolved. Examples // This function should be called after FBInstant.startGameAsync()// resolves.var contextType = FBInstant.context.getType(); Returns ("POST" | "THREAD" | "GROUP" | "SOLO") Type of the current game context.

isSizeBetween( ) This function determines whether the number of participants in the current game context is between a given minimum and maximum, inclusive. If one of the bounds is null only the other bound will be checked against. It will always return the original result for the first call made in a context in a given game play session. Subsequent calls, regardless of arguments, will return the answer to the original query until a context change occurs and the query result is reset. This function should not be called until FBInstant.startGameAsync has resolved. Parameters minSize number? The minimum bound of the context size query. minSize number? The maximum bound of the context size query. maxSize number? Examples console.log(FBInstant.context.isSizeBetween(3, 5)); (Context size = 4)// {answer: true, minSize: 3, maxSize: 5} console.log(FBInstant.context.isSizeBetween(5, 7)); (Context size = 4)// {answer: false, minSize: 5, maxSize: 7} console.log(FBInstant.context.isSizeBetween(2, 10)); (Context size = 3)// {answer: true, minSize: 2, maxSize: 10} console.log(FBInstant.context.isSizeBetween(4, 8)); (Still in same context)// {answer: true, minSize: 2, maxSize: 10} console.log(FBInstant.context.isSizeBetween(3, null)); (Context size = 4)// {answer: true, minSize: 3, maxSize: null} console.log(FBInstant.context.isSizeBetween(null, 3)); (Context size = 4)// {answer: false, minSize: null, maxSize: 3} 控制檯。日誌(FBInstant 。上下文。isSizeBetween (“測試” ,5 )); (上下文大小= 4 )// null
控制檯。日誌(FBInstant 。上下文。isSizeBetween (0 ,100 )); (Context size = null )// null
返回ContextSizeResponse?

switchAsync() 請求切換到特定上下文。如果玩家沒有進入該上下文的許可權,或者玩家沒有提供遊戲進入該上下文的許可權,則會拒絕。否則,當遊戲切換到指定的上下文時,承諾將解決。 引數 id 所需上下文的字串 ID。 例子 控制檯。日誌(FBInstant 。上下文。的getID ()); // 1122334455 FBInstant 。背景 。switchAsync ('1234567890' )。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 1234567890 });

丟擲INVALID_PARAM 丟擲SAME_CONTEXT 引發NETWORK_FAILURE 引發USER_INPUT 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise一個promise,當遊戲切換到指定的上下文時解析,否則拒絕。

chooseAsync() 開啟播放器的上下文選擇對話方塊。如果玩家選擇了可用的上下文,則客戶端將嘗試切換到該上下文,並在成功時解析。否則,如果播放器退出選單或客戶端無法切換到新上下文,則此功能將拒絕。 引數 options 物件?一個物件,指定應提供的上下文的條件。 options.filters 陣列 < ContextFilter >?要應用於上下文建議的過濾器集。 options.maxSize 號碼?理想情況下建議的上下文應具有的最大參與者數。 options.minSize 號碼?理想情況下建議的上下文應具有的最小參與者數量。 例子 控制檯。日誌(FBInstant 。上下文。的getID ()); // 1122334455 FBInstant 。背景 。chooseAsync ()。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 1234567890 });

控制檯。日誌(FBInstant 。上下文。的getID ()); // 1122334455 FBInstant 。背景 。chooseAsync ({ filters :[ 'NEW_CONTEXT_ONLY' ], minSize :3 ,})。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 1234567890 });

丟擲INVALID_PARAM 丟擲SAME_CONTEXT 引發NETWORK_FAILURE 引發USER_INPUT 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise當遊戲切換到使用者選擇的上下文時解析的promise。否則,承諾將拒絕(例如,如果使用者取消對話方塊)。

createAsync() 嘗試建立或切換到指定玩家和當前玩家之間的上下文。如果列出的玩家不是當前玩家的連線玩家,或者玩家未提供進入新上下文的許可,則返回的承諾將拒絕。否則,當遊戲切換到新的上下文時,承諾將解決。 引數 playerID 播放器的字串 ID 例子 控制檯。日誌(FBInstant 。上下文。的getID ()); // 1122334455 FBInstant 。背景 。createAsync ('12345678' )。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 5544332211 });

丟擲INVALID_PARAM 丟擲SAME_CONTEXT 引發NETWORK_FAILURE 引發USER_INPUT 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise一個在遊戲切換到新上下文時解析的promise,否則拒絕。

getPlayersAsync() 獲取#contextplayer物件的陣列,其中包含與當前上下文關聯的活動玩家(在過去90天內玩過遊戲的人)的資訊。這可能包括當前的玩家。 例子 var contextPlayers = FBInstant 。背景。getPlayersAsync ()。然後(功能(播放器){ 控制檯。日誌(球員。地圖(功能(播放器){ 返回{ ID :玩家。的getID (), 名稱:玩家。的getName ()} })); });

// [{id:'123456789',名稱:'Luke'},{id:'987654321',名稱:'Leia'}] 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 丟擲INVALID_OPERATION 返回Promise < Array < ContextPlayer >>

支付 [IN CLOSED BETA]包含與支付和購買遊戲產品相關的功能和屬性。

getCatalogAsync() 獲取遊戲的產品目錄。 例子 FBInstant 。付款。getCatalogAsync ()。然後(功能(目錄){ 控制檯。日誌(目錄); // [{產品編號: '12345',...},...] });
丟擲CLIENT_UNSUPPORTED_OPERATION 投擲PAYMENTS_NOT_INITIALIZED 引發NETWORK_FAILURE 返回Promise < Array < Product >>註冊到遊戲的產品集。

purchaseAsync() 開始了特定產品的採購流程。如果在FBInstant.startGameAsync()解決之前呼叫,將立即拒絕。 引數 purchaseConfig PurchaseConfig購買的配置詳細資訊。 例子 FBInstant 。付款。purchaseAsync ({ productID :'12345' , developerPayload :'foobar' ,})。然後(函式(購買){ 控制檯。日誌(購買); // {產品編號: '12345',purchaseToken: '54321',developerPayload: 'foobar的',...} });

丟擲CLIENT_UNSUPPORTED_OPERATION 投擲PAYMENTS_NOT_INITIALIZED 丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲INVALID_OPERATION 返回Promise < Purchase >在玩家成功購買產品時解析的Promise。否則,它拒絕。

getPurchasesAsync() 獲取所有玩家未使用的購買物品。作為最佳實踐,一旦客戶端表明它已準備好執行與支付相關的操作,遊戲就應該獲取當前玩家的購買。然後,遊戲可以處理和消費等待消費的任何購買。 例子 FBInstant 。付款。getPurchasesAsync ()。然後(函式(購買){ 控制檯。日誌(購買); // [{產品編號: '12345',...},...] });

丟擲CLIENT_UNSUPPORTED_OPERATION 投擲PAYMENTS_NOT_INITIALIZED 引發NETWORK_FAILURE 返回Promise < Array < Purchase >>玩家為遊戲購買的一組購買。

consumePurchaseAsync() 消耗屬於當前玩家的特定購買。在向玩家提供產品效果之前,遊戲應該要求消費所購買的產品。一旦購買成功消費,遊戲應該立即向玩家提供他們購買的效果。 引數 purchaseToken string應該使用的購買的購買標記。 例子 FBInstant 。付款。consumePurchaseAsync ('54321' )。然後(function (){ //購買成功消費!//遊戲現在應該將產品提供給玩家});

丟擲CLIENT_UNSUPPORTED_OPERATION 投擲PAYMENTS_NOT_INITIALIZED 丟擲INVALID_PARAM 引發NETWORK_FAILURE 返回Promise成功使用購買時解析的Promise。

onReady() 設定在付款操作可用時觸發的回撥。 引數 callback 功能付款可用時執行的回撥函式。 例子 FBInstant 。付款。onReady (函式(){ 控制檯。日誌('付款準備好了!' )});
返回void

getLocale() 當前的語言環境。有關 支援的區域設定值的完整列表,請參閱https://origincache.facebook.com/developers/resources/?id=FacebookLocales.xml。使用此選項可確定當前遊戲應使用哪種語言進行本地化。在FBInstant.startGameAsync()結算之前,該值將不準確。 例子 //應該在FBInstant.startGameAsync()//結算後呼叫此函式。var locale = FBInstant 。getLocale (); //'en_US'
返回字串?當前的語言環境。

getPlatform() 遊戲當前執行的平臺。在FBInstant.initializeAsync()結算之前,該值始終為null。 例子 //應該在FBInstant.initializeAsync()//結算後呼叫此函式。var platform = FBInstant 。getPlatform (); //'IOS'
返回平臺?

getSDKVersion() 此SDK版本的字串表示形式。 例子 //應該在FBInstant.initializeAsync()//結算後呼叫此函式。var sdkVersion = FBInstant 。getSDKVersion (); //'2.0'
返回字串 SDK版本。

initializeAsync() 初始化SDK庫。應該在任何其他SDK函式之前呼叫它。 例子 FBInstant 。initializeAsync ()。然後(函式(){ //初始化之前完成多項效能為null。//這是一個好地方來接他們:VAR 區域= FBInstant 。的getLocale (); // 'EN_US' 變種平臺= FBInstant 。getPlatform ( ); // 'IOS' 變種sdkVersion = FBInstant 。getSDKVersion (); // '3.0' 變種playerID = FBInstant 。播放器

。getID (); }); 丟擲INVALID_OPERATION 返回Promise在SDK準備好使用時解析的promise。

setLoadingProgress() 報告遊戲的初始載入進度。 引數 percentage number 0到100之間的數字。 例子 FBInstant 。setLoadingProgress (50 ); //資產載入50% 返回void

getSupportedAPIs() 提供客戶端支援的API函式列表。 例子 //應該在FBInstant.initializeAsync()//結算後呼叫此函式。FBInstant 。getSupportedAPIs (); // ['getLocale','initializeAsync','player.getID','context.getType',...] 返回Array < string >客戶端明確支援的API函式列表。

getEntryPointData() 返回與啟動遊戲的入口點關聯的任何資料物件。 物件的內容是開發人員定義的,可以從不同平臺上的入口點進行。對於較舊的移動客戶端,以及沒有與特定入口點關聯的資料,這將返回null。 應該在FBInstant.startGameAsync()解析後呼叫此函式。 例子 //應該在FBInstant.startGameAsync()//結算後呼叫此函式。const entryPointData = FBInstant 。getEntryPointData (); 返回物件?與當前入口點關聯的資料。

getEntryPointAsync() 返回遊戲啟動的入口點。 在FBInstant.startGameAsync解決之前,不應呼叫此函式。 例子 //應該在FBInstant.startGameAsync()//結算後呼叫此函式。FBInstant 。getEntryPointAsync ()。然後(入口點=> 控制檯。日誌(入口點)); //'admin_message' 返回string使用者啟動遊戲的入口點的名稱

setSessionData() 設定與當前上下文的單個遊戲會話相關聯的資料。 只要遊戲想要更新當前會話資料,就應該呼叫此函式。該會話資料可用於填充各種有效載荷,例如遊戲webhook。 引數 sessionData Object一個任意資料物件,在進行字串化時必須小於或等於1000個字元。 例子 FBInstant 。setSessionData ({ coinsEarned :10 ,eventsSeen :[ 'start' ,...]});
返回void

startGameAsync() 這表明遊戲已完成初始載入並準備開始。返回的promise將解析後,上下文資訊將是最新的。 例子 FBInstant 。startGameAsync ()。然後(函式(){ myGame 。開始(); }); 丟擲INVALID_PARAM 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise一個在遊戲開始時解決的承諾。

shareAsync() 這將呼叫一個對話方塊,讓使用者共享指定的內容,可以是Messenger中的訊息,也可以是使用者時間軸上的帖子。可以將一團資料附加到共享,從共享啟動的每個遊戲會話都可以從FBInstant.getEntryPointData()訪問。在字串化時,此資料必須小於或等於1000個字元。使用者可以選擇取消共享操作並關閉對話方塊,並且無論使用者是否實際共享內容,對話方塊關閉時返回的承諾都將得到解決。 引數 payload SharePayload指定要共享的內容。詳情請見示例。 例子 FBInstant 。shareAsync ({ intent :'REQUEST' , image :base64Picture , text :'X正在尋求幫助!' , 資料:{ myReplayData :'...' },})。然後(function (){ //繼續遊戲。});

丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 丟擲INVALID_OPERATION 返回Promise在共享完成或取消時解析的promise。

updateAsync() 通知Facebook遊戲中發生的更新。這將暫時控制Facebook,Facebook將根據更新的內容決定做什麼。當Facebook將控制權返回給遊戲時,返回的承諾將解決/拒絕。 引數 payload UpdatePayload描述更新的有效內容。 例子 //這將釋出自定義更新。如果遊戲是在Messenger //聊天執行緒中播放的,那麼這將使用指定的//影象和文字訊息將訊息釋出到執行緒中。當人們從這個//訊息啟動遊戲時,那些遊戲會話將能夠通過FBInstant.getEntryPointData()訪問指定的資料blob //。FBInstant 。updateAsync ({ action :'CUSTOM' , cta :'Join The Fight' , image :base64Picture , text :{ default :'X剛入侵Y的村莊!' ,

本地化:{ 
  ar_AR :'X \ u0641 \ u0642 \ u0637 \ u063A \ u0632 \ u062A' + '\ u0642 \ u0631 \ u064A \ u0629 Y!' ,
  en_US :'X只是入侵了Y的村莊!' ,
  es_LA :'\ u00A1X acaba de invadir el pueblo de Y!' ,} } 
複製程式碼

template :'VILLAGE_INVASION' , data :{ myReplayData :'...' }, 策略:'IMMEDIATE' , 通知:'NO_PUSH' ,})。

    function (){ //在釋出更新後關閉遊戲。FBInstant 。退出(); }); 
複製程式碼

丟擲INVALID_PARAM 丟擲PENDING_REQUEST 丟擲INVALID_OPERATION 返回Promise當Facebook將控制權交還給遊戲時解決的承諾。

switchGameAsync() 請求客戶端切換到其他即時遊戲。如果交換機失敗,API將拒絕 - 否則,客戶端將載入新遊戲。 引數 appID string要切換到的即時遊戲的應用程式ID。該應用程式必須是即時遊戲,並且必須屬於與當前遊戲相同的業務。要將不同遊戲與同一業務相關聯,您可以使用Business Manager: https: //developers.facebook.com/docs/apps/business-manager#update-business。 data 物件?可選的資料有效負載。這將被設定為切換到的遊戲的入口點資料。字串化時必須小於或等於1000個字元。 例子 FBInstant 。switchGameAsync ('12345678' )。catch (function (e ){ // Handle game change failure });

引發USER_INPUT 丟擲INVALID_PARAM 丟擲PENDING_REQUEST 引發CLIENT_REQUIRES_UPDATE 返回Promise

canCreateShortcutAsync() 返回使用者是否有資格請求建立快捷方式。 如果createShortcutAsync已被呼叫此會話,或者使用者不符合建立快捷方式的條件,則返回false。 例子 FBInstant 。canCreateShortcutAsync ()。然後(函式(canCreateShortcut ){ 如果(canCreateShortcut ){ FBInstant 。createShortcutAsync () 。然後(函式(){ //建立快捷方式}) 。捕獲(功能(){ //快捷方式沒有建立}); } });

丟擲PENDING_REQUEST 引發CLIENT_REQUIRES_UPDATE 丟擲INVALID_OPERATION 返回Promise < boolean >如果遊戲可以請求玩家建立遊戲的快捷方式,則解析為true,否則返回false

createShortcutAsync() 如果使用者符合條件,則提示使用者建立遊戲的快捷方式每個會話只能呼叫一次。(參見canCreateShortcutAsync) 例子 FBInstant 。canCreateShortcutAsync ()。然後(函式(canCreateShortcut ){ 如果(canCreateShortcut ){ FBInstant 。createShortcutAsync () 。然後(函式(){ //建立快捷方式}) 。捕獲(功能(){ //快捷方式沒有建立}); } });

引發USER_INPUT 丟擲PENDING_REQUEST 引發CLIENT_REQUIRES_UPDATE 丟擲INVALID_OPERATION 返回Promise

放棄( ) 退出遊戲。 例子 FBInstant 。退出(); 返回void

logEvent() 使用FB Analytics記錄應用程式事件。 有關FB Analytics的更多詳細資訊,請參閱 developers.facebook.com/docs/javasc… 引數 eventName string事件的名稱。必須為2到40個字元,並且只能包含“”,“ - ”,“和”字母數字字元。 valueToSum number FB Analytics可以計算總和的可選數值。 parameters Object一個可選物件,最多可包含25個與事件一起記錄的鍵值對。鍵必須為2到40個字元,並且只能包含“”,“ - ”,“和”字母數字字元。值的長度必須小於100個字元。 例子 var logged = FBInstant 。logEvent ('my_custom_event' ,42 ,{ custom_property :'custom_value' },);

返回APIError?事件未能記錄時的錯誤; 否則返回null。

onPause() 設定在觸發暫停事件時觸發的回撥。 引數 func 功能發生暫停事件時呼叫的函式。 例子 FBInstant 。在onPause (函式(){ 控制檯。日誌('暫停事件被觸發!' ); }) 返回void

getInterstitialAdAsync() 嘗試建立插頁式廣告的例項。然後可以預載入並呈現該例項。 引數 placementID 字串在受眾網路設定中設定的展示位置ID。 例子 FBInstant 。getInterstitialAdAsync ('my_placement_id' ,)。然後(函式(間質性){ 間質性。getPlacementID (); // 'my_placement_id' });

丟擲ADS_TOO_MANY_INSTANCES 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise使用#adinstance解析的 promise,如果無法建立,則拒絕#apierror。

getRewardedVideoAsync() 嘗試建立獎勵視訊的例項。然後可以預載入並呈現該例項。 引數 placementID 字串在受眾網路設定中設定的展示位置ID。 例子 FBInstant 。getRewardedVideoAsync ('my_placement_id' ,)。然後(函式(rewardedVideo ){ rewardedVideo 。getPlacementID (); // 'my_placement_id' });

丟擲ADS_TOO_MANY_INSTANCES 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise使用#adinstance解析的 promise,如果無法建立,則拒絕#apierror。

matchPlayerAsync() 嘗試將當前播放器與尋找其他人的其他使用者進行匹配。如果成功,將建立包含匹配的玩家的新Messenger組執行緒,並且播​​放器將被上下文切換到該執行緒。一個匹配執行緒中的預設最小和最大玩家數分別為2和20,具體取決於在同一時間內嘗試匹配的玩家數量。可以在fbapp-config.json中更改這些值。 有關fbapp-config.json的文件,請參閱[Bundle Config文件] developers.facebook.com/docs/games/… 引數 matchTag 字串?有關用於將其與類似玩家分組的玩家的可選額外資訊。玩家只能與具有完全相同標籤的其他玩家分組。標籤只能包含字母,數字和下劃線,長度不得超過100個字元。 switchContextWhenMatched boolean可選的額外引數,指定在找到匹配項時是否應立即將播放器切換到新上下文。預設情況下,這將是false,這意味著玩家在匹配後需要明確按下播放以切換到新的上下文。 例子 FBInstant 。matchPlayerAsync ('level1' )。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 12345 });

FBInstant 。matchPlayerAsync ()。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 3456 });

FBInstant 。matchPlayerAsync (null ,true )。然後(函式(){ 控制檯。登入(FBInstant 。上下文。的getID ()); // 3456 });

丟擲INVALID_PARAM 引發NETWORK_FAILURE 引發USER_INPUT 丟擲PENDING_REQUEST 丟擲CLIENT_UNSUPPORTED_OPERATION 丟擲INVALID_OPERATION 返回Promise一個promise,當玩家被新增到組執行緒並切換到執行緒的上下文時解析。

checkCanPlayerMatchAsync() 檢查當前播放器是否符合matchPlayerAsync API的條件。 例子 FBInstant 。checkCanPlayerMatchAsync ()。然後(canMatch => { 如果(canMatch ){ FBInstant 。matchPlayerAsync ('1級' ); } });

引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 返回Promise < boolean >如果玩家有資格與其他玩家匹配則返回true的保證,否則返回false。

getLeaderboardAsync() 獲取屬於此即時遊戲的特定排行榜。 引數 name string排行榜的名稱。即時遊戲的每個排行榜都必須有自己獨特的名稱。 例子 FBInstant 。getLeaderboardAsync ('my_awesome_leaderboard' )。然後(排行榜=> { 控制檯。登入(排行榜。的getName ()); // 'my_awesome_leaderboard' });

丟擲LEADERBOARD_NOT_FOUND 引發NETWORK_FAILURE 丟擲CLIENT_UNSUPPORTED_OPERATION 丟擲INVALID_OPERATION 丟擲INVALID_PARAM 返回Promise < Leaderboard >使用匹配的排行榜解析的承諾,如果找不到,則拒絕。

LocalizationsDict 表示從語言環境到給定字串的翻譯的對映。每個屬性都是xx_XX形式的可選五字元Facebook區域程式碼。有關 支援的區域設定程式碼的完整列表,請參閱https://origincache.facebook.com/developers/resources/?id=FacebookLocales.xml。 型別:物件

APIERROR Instant Games SDK返回的API錯誤

碼 相關的錯誤程式碼 鍵入:ErrorCodeType

資訊 描述錯誤的訊息 輸入:string

SignedPlayerInfo 代表有關播放器的資訊以及簽名,以驗證它確實來自Facebook。

getPlayerID() 獲取播放器的ID。 例子 FBInstant 。球員。getSignedPlayerInfoAsync ()。然後(函式(結果){ 結果。getPlayerID (); //相同的值FBInstant.player.getID()});

返回string字串播放器的ID

getSignature() 用於驗證此物件的簽名確實來自Facebook。該字串是base64url編碼的,並根據OAuth 2.0規範使用您的App Secret的HMAC版本進行簽名。 您可以使用以下4個步驟對其進行驗證: 將簽名拆分為由“。”分隔的兩個部分。字元。 使用base64url編碼解碼第一部分(編碼簽名)。 使用base64url編碼解碼第二部分(響應有效負載),該編碼應該是具有以下欄位的JSON物件的字串表示:** algorithm - 始終等於HMAC-SHA256 ** issued_at - 此響應時的unix時間戳發出。** player_id - 播放器的唯一識別符號。** request_payload - 呼叫FBInstant.player.getSignedPlayerInfoAsync時指定的requestPayload字串。 使用HMAC SHA-256和您的app secret來雜湊整個響應有效負載字串,並確認它等於編碼簽名。 您可能還希望驗證響應有效內容中的issued_at時間戳,以確保最近發出請求。 簽名驗證應該只在您的伺服器上進行。永遠不要在客戶端這樣做,因為它會危及您的應用程式金鑰。 例子 FBInstant 。球員。getSignedPlayerInfoAsync ()。然後(函式(結果){ 結果。getSignature (); // Eii6e636mz5J47sfqAYEK40jYAwoFqi3x5bxHkPG4Q4.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUwMDM5ODY3NSwicGxheWVyX2lkIjoiMTI0OTUyNTMwMTc1MjIwMSIsInJlcXVlc3RfcGF5bG9hZCI6Im15X2ZpcnN0X3JlcXVlc3QifQ });

返回string簽名字串。

ConnectedPlayer 表示有關連線到當前玩家的玩家的資訊。

getID() 獲取已連線播放器的ID。 返回string連線的播放器的ID

getName() 獲取玩家的全名。 返回字串?玩家的全名

getPhoto() 獲取播放器的公開個人資料照片。 返回字串?玩家公開個人資料照片的網址

ContextPlayer 表示有關當前玩家正在玩的上下文中的玩家的資訊。

getID() 獲取上下文播放器的ID。 返回string上下文播放器的ID

getName() 獲取播放器的本地化顯示名稱。 返回字串?播放器的本地化顯示名稱。

getPhoto() 獲取播放器的公開個人資料照片。 返回字串?玩家公開個人資料照片的網址

AdInstance 表示廣告的例項。

getPlacementID() 返回此廣告例項的受眾群體展示位置ID。

loadAsync() 預載入廣告。返回的promise在預載入完成時解析,如果失敗則拒絕。 例子 FBInstant 。getInterstitialAdAsync ('my_placement_id' ,)。然後(函式(間質性){ 返回間質性。loadAsync (); })。然後(function (){ // Ad loaded });

丟擲ADS_FREQUENT_LOAD 丟擲ADS_NO_FILL 丟擲INVALID_PARAM 引發NETWORK_FAILURE 返回Promise

showAsync() 展示廣告。當使用者完成觀看廣告時,返回的承諾會解決,如果廣告在廣告期間未能出現或已關閉,則拒絕承諾。 例子 var ad = null ; FBInstant 。getRewardedVideoAsync ('my_placement_id' ,)。然後(函式(rewardedVideo ){ 廣告= rewardedVideo ; 返回廣告。loadAsync (); })。然後(函式(){ //載入廣告返回廣告。showAsync (); })。然後(function (){ //廣告觀看});

丟擲ADS_NOT_LOADED 丟擲INVALID_PARAM 引發NETWORK_FAILURE 丟擲INVALID_OPERATION 返回Promise

產品 代表遊戲的產品資訊。 型別:物件 屬性 title string產品的標題 productID string產品的遊戲指定識別符號 description 字串?產品說明 imageURI 字串?指向產品相關影象的連結 price string產品的價格 priceCurrencyCode string產品的貨幣程式碼

ContextFilter 可以應用於上下文選擇操作'NEW_CONTEXT_ONLY'的過濾器 - 更喜歡僅表面上下文之前尚未播放的遊戲。'INCLUDE_EXISTING_CHALLENGES' - 包括“現有挑戰”部分,該部分顯示了玩家所屬的主動上場情節。'NEW_PLAYERS_ONLY' - 在包含個人的部分中,更喜歡沒有玩過遊戲的人。 型別:("NEW_CONTEXT_ONLY"| "INCLUDE_EXISTING_CHALLENGES"| "NEW_PLAYERS_ONLY")

平臺 表示使用者正在播放的當前平臺。 型別:( "IOS"| "ANDROID"| "WEB"| "MOBILE_WEB")

ContextSizeResponse 如果當前上下文大小介於物件中指定的minSize和maxSize值之間,則answer欄位為true,否則為false。 鍵入:{answer:boolean,minSize:number?,maxSize:number?}

採購 代表個人購買遊戲產品。 型別:物件 屬性 developerPayload 字串?購買產品期間提供的開發人員指定的字串 paymentID string購買交易的識別符號 productID string產品的遊戲指定識別符號 purchaseTime string發生購買時的Unix時間戳 purchaseToken 字串表示可用於消費購買的購買的標記 signedRequest SignedPurchaseRequest伺服器簽名的購買請求編碼

排行榜 即時遊戲排行榜

getName() 排行榜的名稱。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 控制檯。日誌(排行榜。的getName ()); // my_leaderboard });

返回字串

getContextID() 排行榜與之關聯的上下文的ID,如果排行榜未與特定上下文繫結,則為null。 例子 FBInstant 。getLeaderboardAsync ('contextual_leaderboard' )。然後(函式(排行榜){ 控制檯。登入(排行榜。getContextID ()); // 12345678 });

FBInstant 。getLeaderboardAsync ('global_leaderboard' )。然後(函式(排行榜){ 控制檯。日誌(排行榜。getContextID ()); //空});

返回字串?

getEntryCountAsync() 獲取排行榜中玩家條目的總數。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getEntryCountAsync (); }) 。然後(函式(計數){ 控制檯。日誌(計數); }); // 24

引發NETWORK_FAILURE 丟擲RATE_LIMITED 返回Promise < number >播放器的唯一識別符號。

setScoreAsync() 更新玩家的分數。如果玩傢俱有現有分數,則只有在新分數優於其時才會替換舊分數。注意:如果排行榜與特定上下文相關聯,則遊戲必須在該上下文中為玩家設定分數。 引數 score number玩家的新分數。必須是64位整數。 extraData string?= // 2與儲存的分數關聯的後設資料。大小必須小於2KB。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。setScoreAsync (42 ,'{種族: “小精靈”,級別:3}' ); }) 。然後(函式(條目){ 控制檯。日誌(條目。getScore ()); // 42 控制檯。日誌(條目。

getExtraData ()); //'{race:“elf”,等級:3}' }); 
複製程式碼

丟擲LEADERBOARD_WRONG_CONTEXT 引發NETWORK_FAILURE 丟擲INVALID_PARAM 丟擲INVALID_OPERATION 丟擲RATE_LIMITED 返回Promise < LeaderboardEntry >在更新後使用播放器的當前排行榜條目解析。

getPlayerEntryAsync() 檢索當前播放器的排行榜條目,如果播放器尚未設定,則返回null。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getPlayerEntryAsync (); }) 。然後(函式(條目){ 控制檯。日誌(條目。getRank ()); // 2 控制檯。日誌(條目。getScore ()); // 42 控制檯。

 日誌(入口。getExtraData ()); //'{race:“elf”,等級:3}' }); 
複製程式碼

引發NETWORK_FAILURE 丟擲INVALID_OPERATION 丟擲RATE_LIMITED 返回Promise < LeaderboardEntry >?解決了播放器當前的排行榜條目。

getEntriesAsync() 檢索一組排行榜條目,按排行榜中的分數排名排序。 引數 count number嘗試從排行榜獲取的條目數。如果未指定,則預設為10。目前,每個查詢最多可以獲取100個條目。 offset number從排行榜頂部開始的條目,即從中獲取條目。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getEntriesAsync (); }) 。然後(功能(項){ 控制檯。日誌(條目。長度); // 10 控制檯。登入(條目[ 0 ]。getRank ()); // 1

控制檯。log (entries [ 0 ] .getScore ()); // 42 
臺。log (entries [ 1 ] .getRank ()); // 2 
控制檯。log (entries [ 1 ] .getScore ()); // 40 });   
複製程式碼

FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getEntriesAsync (5 ,3 ); }) 。然後(功能(項){ 控制檯。日誌(條目。長度); // 5 控制檯。日誌(條目[ 0 ]。

getRank ()); // 4 
控制檯。log (entries [ 0 ] .getScore ()); // 34 
控制檯。log (entries [ 1 ] .getRank ()); // 5 
控制檯。log (entries [ 1 ] .getScore ()); // 31 });    
複製程式碼

引發NETWORK_FAILURE 丟擲RATE_LIMITED 返回Promise < Array < LeaderboardEntry >>使用與查詢匹配的排行榜條目解析。

getConnectedPlayerEntriesAsync() 檢索當前玩家的連線玩家(包括當前玩家)的排行榜得分條目,按照連線玩家組中的本地排名排序。 引數 count number嘗試從排行榜獲取的條目數。如果未指定,則預設為10。目前,每個查詢最多可以獲取100個條目。 offset number從要獲取的有序連線玩家得分條目集的偏移量。 例子 FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getConnectedPlayerEntriesAsync (); }) 。然後(功能(項){ 控制檯。日誌(條目。長度); // 10 控制檯。登入(條目[ 0 ]。getRank ()); // 1

控制檯。log (entries [ 0 ] .getScore ()); // 42 
臺。log (entries [ 1 ] .getRank ()); // 2 
控制檯。log (entries [ 1 ] .getScore ()); // 40 });   
複製程式碼

FBInstant 。getLeaderboardAsync ('my_leaderboard' )。然後(函式(排行榜){ 返回排行榜。getConnectedPlayerEntriesAsync (5 ,3 ); }) 。然後(功能(項){ 控制檯。日誌(條目。長度); // 5 控制檯。日誌(條目[ 0 ]。

getRank ()); // 4 
控制檯。log (entries [ 0 ] .getScore ()); // 34 
控制檯。log (entries [ 1 ] .getRank ()); // 5 
控制檯。log (entries [ 1 ] .getScore ()); // 31 });    
複製程式碼

引發NETWORK_FAILURE 丟擲RATE_LIMITED 返回Promise < Array < LeaderboardEntry >>使用與查詢匹配的排行榜條目解析。

SharePayload 表示要由使用者共享的內容。 型別:物件 屬性 intent ("INVITE"| "REQUEST"| "CHALLENGE"| "SHARE")表示共享的意圖。 image string要共享的base64編碼影象。 text string要共享的文字訊息。 data 物件?要附加到共享的資料blob。從共享啟動的所有遊戲會話都可以通過FBInstant.getEntryPointData()訪問此blob。

UpdateAction 表示要執行的更新操作的型別。 屬性 CUSTOM 字串自定義更新,包含遊戲指定的所有內容。 LEADERBOARD 字串與即時遊戲排行榜相關聯的更新。

錯誤程式碼 Instant Games API可能返回的錯誤程式碼 屬性 ADS_FREQUENT_LOAD 字串廣告過於頻繁地載入。 ADS_NO_FILL 字串我們無法向當前使用者投放廣告。如果使用者在其裝置上選擇停用針對使用者興趣的廣告,或者我們沒有為該使用者展示廣告資源,則可能會發生這種情況。 ADS_NOT_LOADED string嘗試顯示尚未成功載入的廣告。 ADS_TOO_MANY_INSTANCES 字串併發廣告例項太多。在建立新廣告例項之前載入並顯示它們。 ANALYTICS_POST_EXCEPTION 字串分析API在嘗試釋出事件時遇到問題。 CLIENT_REQUIRES_UPDATE string [已棄用] - 客戶端需要更新才能訪問返回此結果的功能。如果在Web上返回此結果,則表示Web客戶端尚不支援該功能。在v5.0及更高版本中不推薦使用CLIENT_UNSUPPORTED_OPERATION CLIENT_UNSUPPORTED_OPERATION string客戶端不支援當前操作。這可能是由於客戶端版本或平臺缺乏支援,或者因為遊戲或播放器不允許操作。 INVALID_OPERATION string請求的操作無效或當前遊戲狀態。這可能包括違反限制的請求,例如超出儲存閾值,或者在某種狀態下不可用,例如在獨立上下文中生成特定於上下文的請求。 INVALID_PARAM string傳遞給API的引數無效。可以指示不正確的型別,無效的引數數量或語義問題(例如,將不可序列化的物件傳遞給序列化函式)。 LEADERBOARD_NOT_FOUND string找不到具有所請求名稱的排行榜。排行榜尚未存在,或者名稱與遊戲的任何已註冊排行榜配置都不匹配。 LEADERBOARD_WRONG_CONTEXT string嘗試寫入與當前正在播放遊戲之外的上下文關聯的排行榜。 NETWORK_FAILURE string客戶端遇到網路請求問題。這可能是由於一個短暫的問題,例如玩家的網際網路連線下降。 PAYMENTS_NOT_INITIALIZED 字串客戶端尚未完成設定付款或未接受付款API呼叫。 PENDING_REQUEST string表示由於與此衝突衝突的現有請求而導致的拒絕。例如,當另一個依賴於Facebook UI的請求待處理時,我們將拒絕任何會顯示Facebook UI的呼叫。 RATE_LIMITED string過於頻繁地呼叫某些API或操作。這可能是由於遊戲在很短的時間內呼叫特定API的次數過多。降低請求率應該會導致此錯誤消失。 SAME_CONTEXT string遊戲嘗試執行上下文切換到當前上下文。 UNKNOWN string發生未知或未指定的問題。這是客戶端未指定程式碼時返回的預設錯誤程式碼。 USER_INPUT string使用者做出了導致拒絕的選擇。例如,如果遊戲調出Context Switch對話方塊並且播放器將其關閉,則此錯誤程式碼將包含在promise promise中。 例子 FBInstant 。startGameAsync ()。捕捉(函式(É ){ 控制檯。日誌(ë ); }); // {code:'CLIENT_UNSUPPORTED_OPERATION',訊息:'...'}

ErrorCodeType 一個即時遊戲錯誤程式碼,#errorcode之一 輸入:string

SignedPurchaseRequest 輸入:string 例子 Eii6e636mz5J47sfqAYEK40jYAwoFqi3x5bxHkPG4Q4 。eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUwMDM5ODY3NSwicGxheWVyX2lkIjoiMTI0OTUyNTMwMTc1MjIwMSIsInJlcXVlc3RfcGF5bG9hZCI6Im15X2ZpcnN0X3JlcXVlc3QifQ

PurchaseConfig 註冊到遊戲的產品的購買請求的配置。 型別:物件 屬性 productID string要購買的產品的識別符號 developerPayload 字串?可選的開發人員指定的有效負載,包含在已退回購買的已簽名請求中。

CustomUpdatePayload 表示自定義更新FBInstant.updateAsync。請注意,如果未提供本地化內容,則Facebook提供的本地化字串將用於號召性用語和文字。 該default字串應該是英文。 型別:物件 屬性 action UpdateAction對於自定義更新,這應該是“CUSTOM”。 template 此自定義更新正在使用的模板的字串 ID。模板應該在fbapp-config.json中預定義。有關fbapp-config.json的文件,請參閱[Bundle Config文件]developers.facebook.com/docs/games/… cta (string?| LocalizableContent?)可選的號召性用語按鈕文字。預設情況下,我們將使用本地化的“播放”作為按鈕文字。要提供自己的號召性用語的本地化版本,請使用預設cta作為'default'的值傳遞物件,將另一個物件對映到翻譯作為'localizations'的值。 image string base64編碼影象的資料URL。 text (string | LocalizableContent)一條文字訊息,或一個預設文字為'default'的物件,另一個物件將語言環境鍵對映為'localizations'的值。 data 物件?要附加到更新的資料blob。從更新啟動的所有遊戲會話都可以通過FBInstant.getEntryPointData()訪問此blob。字串化時必須小於或等於1000個字元。 strategy 字串?指定應如何傳遞更新。這可以是以下之一:'IMMEDIATE' - 應立即釋出更新。'LAST' - 更新應在遊戲會話結束時釋出。使用“最後”策略傳送的最新更新將是傳送的更新。'IMMEDIATE_CLEAR' - 更新立即釋出,並清除所有其他待處理的更新(例如使用'LAST'策略傳送的更新)。如果未指定策略,則預設為“IMMEDIATE”。 notification 字串?指定自定義更新的通知設定。這可以是'NO_PUSH'或'PUSH',預設為'NO_PUSH'。僅對具有高訊號且可立即為收件人操作的更新使用推送通知。另請注意,根據使用者設定和平臺策略,並不總能保證推送通知。

LeaderboardUpdatePayload 表示FBInstant.updateAsync的排行榜更新。 型別:物件 屬性 action UpdateAction對於排行榜更新,這應該是'LEADERBOARD'。文字。預設情況下,我們將使用本地化的“立即播放”作為按鈕文字。 name string要在更新中顯示的排行榜的名稱。 text 字串?可選的簡訊。如果未指定,則將提供本地化回退訊息。

LocalizableContent 表示具有本地化的字串和要重新使用的預設值。 型別:物件 屬性 default string如果檢視者的語言環境不是本地化物件中的鍵,則使用的字串的預設值。 localizations LocalizationsDict指定每個語言環境中用於檢視者的字串。有關 支援的區域設定值的完整列表,請參閱 origincache.facebook.com/developers/…

LeaderboardEntry 即時遊戲排行榜的分數條目

getScore() 獲取與條目關聯的分數。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。登入(條目。getScore ()); // 9001 });

返回數字返回整數分數值。

getFormattedScore() 獲取與條目關聯的分數,使用與排行榜關聯的分數格式進行格式化。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。登入(條目。getFormattedScore ()); // '900.01米});

返回字串返回格式化的分數。

getTimestamp() 獲取上次更新排行榜條目的時間戳。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。登入(條目。getTimestamp ()); // 1515806355 });

返回number返回Unix時間戳。

getRank() 獲取排行榜中玩家得分的排名。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。登入(條目。getRank ()); // 2 });

返回數字返回條目的排行榜排名。

getExtraData() 獲取與分數關聯的開發人員指定的有效內容,如果未設定,則返回null。 例子 排行榜。setScoreAsync (42 ,'{race:“elf”,level:3}' ); 。然後(函式(條目){ 控制檯。登入(條目。getExtraData ()); // '{種族: “小精靈”,級別:3}' });

返回字串?與分數關聯的可選開發人員指定的有效負載。

getPlayer() 獲取有關與條目關聯的播放器的資訊。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。日誌(條目。getPlayer ()。的getName ()); //薩利});

返回LeaderboardPlayer

LeaderboardPlayer 有關與分數條目相關聯的玩家的詳細資訊。

getName() 獲取播放器的本地化顯示名稱。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。日誌(條目。getPlayer ()。的getName ()); //薩利});

返回字串播放器的本地化顯示名稱。

getPhoto() 返回玩家公開個人資料照片的網址。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。日誌(條目。getPlayer ()。getPhoto ()); // <PHOTO_URL> });

返回字串?網址為玩家的公開個人資料照片。

getID() 獲取遊戲的唯一識別符號。 例子 排行榜。setScoreAsync (9001 )。然後(函式(條目){ 控制檯。登入(條目。getPlayer ()。的getID ()); // 12345678 });

返回字串?玩家的遊戲範圍識別符號。 以下是英文版 API Reference v6.2

Changelog 1.Connected Player Score Entries Introduces the new Leaderboard.getConnectedPlayerEntriesAsync() API, which fetches the score entries of the current player's connected players from the leaderboard.

FBInstant Top level namespace for the Instant Games SDK.

player Contains functions and properties related to the current player.

getID( ) A unique identifier for the player. A Facebook user's player ID will remain constant, 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. Examples // This function should be called after FBInstant.initializeAsync()// resolves.var playerID = FBInstant.player.getID(); Returns string? A unique identifier for the player.

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. Parameters requestPayload string? A developer-specified payload to include in the signed response. Examples // This function should be called after FBInstant.initializeAsync()// resolves.FBInstant.player.getSignedPlayerInfoAsync('my_metadata') .then(function (result) { // The verification of the ID and signature should happen on server side. SendToMyServer( result.getPlayerID(), // same value as FBInstant.player.getID() result.getSignature(), 'GAIN_COINS', 100); }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves with a #signedplayerinfo object.

canSubscribeBotAsync( ) Returns a promise that resolves with whether the player can subscribe to the game bot or not. Examples // This function should be called before FBInstant.player.subscribeBotAsync()FBInstant.player.canSubscribeBotAsync().then( can_subscribe => console.log(can_subscribe));// 'true' Returns Promise Whether a player can subscribe to the game bot or not. Developer can only call subscribeBotAsync() after checking canSubscribeBotAsync(), and the player will only be able to see this bot subscription dialog once for a specific game.

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. Examples FBInstant.player.subscribeBotAsync().then( // Player is subscribed to the bot).catch(function (e) { // Handle subscription failure}); Throws INVALID_PARAM Throws PENDING_REQUEST Throws CLIENT_REQUIRES_UPDATE Returns Promise A promise that resolves if player successfully subscribed to the game bot, or rejects if request failed or player chose to not subscribe.

getName( ) The player's localized display name. This function should not be called until FBInstant.startGameAsync() has resolved. Examples // This function should be called after FBInstant.startGameAsync()// resolves.var playerName = FBInstant.player.getName(); Returns string? The player's localized 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.startGameAsync() 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'. Examples var playerImage = new Image(); playerImage.crossOrigin = 'anonymous';// This function should be called after FBInstant.startGameAsync()// resolves. playerImage.src = FBInstant.player.getPhoto(); Returns string? Url to the player's public profile photo.

getDataAsync( ) Retrieve data from the designated cloud storage of the current player. Parameters keys Array An array of unique keys to retrieve data for. Examples FBInstant.player .getDataAsync(['achievements', 'currentLife']) .then(function(data) { console.log('data is loaded'); var achievements = data['achievements']; var currentLife = data['currentLife']; }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise 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.

setDataAsync( ) 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. Parameters data Object 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. Examples FBInstant.player .setDataAsync({ achievements: ['medal1', 'medal2', 'medal3'], currentLife: 300, }) .then(function() { console.log('data is set'); }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise 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.

flushDataAsync( ) Immediately flushes any changes to the player data to the designated cloud storage. This function is expensive, and should primarily be used for critical changes where persistence needs to be immediate and known by the game. Non-critical changes should rely on the platform to persist them in the background. NOTE: Calls to player.setDataAsync will be rejected while this function's result is pending. Examples FBInstant.player .setDataAsync({ achievements: ['medal1', 'medal2', 'medal3'], currentLife: 300, }) .then(FBInstant.player.flushDataAsync) .then(function() { console.log('Data persisted to FB!'); }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves when changes have been persisted successfully, and rejects if the save fails.

getStatsAsync( ) Retrieve stats from the designated cloud storage of the current player. Parameters keys Array? An optional array of unique keys to retrieve stats for. If the function is called without it, it will fetch all stats. Examples FBInstant.player .getStatsAsync(['level', 'zombiesSlain']) .then(function(stats) { console.log('stats are loaded'); var level = data['level']; var zombiesSlain = data['zombiesSlain']; }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise 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.

setStatsAsync( ) Set stats to be saved to the designated cloud storage of the current player. Parameters stats Object An object containing a set of key-value pairs that should be persisted to cloud storage as stats, which can be surfaced or used in a variety of ways to benefit player engagement. The object must contain only numerical values - any non-numerical values will cause the entire modification to be rejected. Examples FBInstant.player .setStatsAsync({ level: 5, zombiesSlain: 27, }) .then(function() { console.log('data is set'); }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise 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 validated and has been scheduled to be saved. It also guarantees that all values that were set are now available in player.getStatsAsync.

incrementStatsAsync( ) Increment stats saved in the designated cloud storage of the current player. Parameters increments Object An object containing a set of key-value pairs indicating how much to increment each stat in cloud storage. The object must contain only numerical values - any non-numerical values will cause the entire modification to be rejected. Examples FBInstant.player .incrementStatsAsync({ level: 1, zombiesSlain: 17, rank: -1, }) .then(function(stats)) { console.log('increments have been made! New values'); var level = data['level']; var zombiesSlain = data['zombiesSlain']; }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves with an object which contains the updated key-value pairs for each key specified in the input dictionary. NOTE: The promise resolving does not necessarily mean that the changes have already been persisted. Rather, it means that the increments were valid and have been scheduled to be performed. It also guarantees that all values that were incremented are now available in player.getStatsAsync.

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. Examples var connectedPlayers = FBInstant.player.getConnectedPlayersAsync() .then(function(players) { console.log(players.map(function(player) { return { id: player.getID(), name: player.getName(), } })); });// [{id: '123456789', name: 'Paul Atreides'}, {id: '987654321', name: 'Duncan Idaho'}] Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise<Array> A promise that resolves with a list of connected player objects. NOTE: This function should not be called until FBInstant.startGameAsync() has resolved.

context Contains functions and properties related to the current game context.

getID( ) A unique identifier for the current game context. This represents a specific context that the game is being played in (for example, a particular messenger conversation or facebook post). The identifier will be null if game is being played in a solo context. This function should not be called until FBInstant.startGameAsync has resolved. Examples // This function should be called after FBInstant.startGameAsync()// resolves.var contextID = FBInstant.context.getID(); Returns string? A unique identifier for the current game context.

getType( ) The type of the current game context. POST - A facebook post. THREAD - A messenger thread. GROUP - A facebook group. SOLO - Default context, where the player is the only participant. This function should not be called until FBInstant.startGameAsync has resolved. Examples // This function should be called after FBInstant.startGameAsync()// resolves.var contextType = FBInstant.context.getType(); Returns ("POST" | "THREAD" | "GROUP" | "SOLO") Type of the current game context.

isSizeBetween( ) This function determines whether the number of participants in the current game context is between a given minimum and maximum, inclusive. If one of the bounds is null only the other bound will be checked against. It will always return the original result for the first call made in a context in a given game play session. Subsequent calls, regardless of arguments, will return the answer to the original query until a context change occurs and the query result is reset. This function should not be called until FBInstant.startGameAsync has resolved. Parameters minSize number? The minimum bound of the context size query. minSize number? The maximum bound of the context size query. maxSize number? Examples console.log(FBInstant.context.isSizeBetween(3, 5)); (Context size = 4)// {answer: true, minSize: 3, maxSize: 5} console.log(FBInstant.context.isSizeBetween(5, 7)); (Context size = 4)// {answer: false, minSize: 5, maxSize: 7} console.log(FBInstant.context.isSizeBetween(2, 10)); (Context size = 3)// {answer: true, minSize: 2, maxSize: 10} console.log(FBInstant.context.isSizeBetween(4, 8)); (Still in same context)// {answer: true, minSize: 2, maxSize: 10} console.log(FBInstant.context.isSizeBetween(3, null)); (Context size = 4)// {answer: true, minSize: 3, maxSize: null} console.log(FBInstant.context.isSizeBetween(null, 3)); (Context size = 4)// {answer: false, minSize: null, maxSize: 3} console.log(FBInstant.context.isSizeBetween("test", 5)); (Context size = 4)// null console.log(FBInstant.context.isSizeBetween(0, 100)); (Context size = null)// null Returns ContextSizeResponse?

switchAsync( ) Request a switch into a specific context. If the player does not have permission to enter that context, or if the player does not provide permission for the game to enter that context, this will reject. Otherwise, the promise will resolve when the game has switched into the specified context. Parameters id string ID of the desired context. Examples console.log(FBInstant.context.getID());// 1122334455FBInstant.context .switchAsync('1234567890') .then(function() { console.log(FBInstant.context.getID()); // 1234567890 }); Throws INVALID_PARAM Throws SAME_CONTEXT Throws NETWORK_FAILURE Throws USER_INPUT Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves when the game has switched into the specified context, or rejects otherwise.

chooseAsync( ) Opens a context selection dialog for the player. If the player selects an available context, the client will attempt to switch into that context, and resolve if successful. Otherwise, if the player exits the menu or the client fails to switch into the new context, this function will reject. Parameters options Object? An object specifying conditions on the contexts that should be offered. options.filters Array? The set of filters to apply to the context suggestions. options.maxSize number? The maximum number of participants that a suggested context should ideally have. options.minSize number? The minimum number of participants that a suggested context should ideally have. Examples console.log(FBInstant.context.getID());// 1122334455FBInstant.context .chooseAsync() .then(function() { console.log(FBInstant.context.getID()); // 1234567890 }); console.log(FBInstant.context.getID());// 1122334455FBInstant.context .chooseAsync({ filters: ['NEW_CONTEXT_ONLY'], minSize: 3, }) .then(function() { console.log(FBInstant.context.getID()); // 1234567890 }); Throws INVALID_PARAM Throws SAME_CONTEXT Throws NETWORK_FAILURE Throws USER_INPUT Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves when the game has switched into the context chosen by the user. Otherwise, the promise will reject (if the user cancels out of the dialog, for example).

createAsync( ) Attempts to create or switch into a context between a specified player and the current player. The returned promise will reject if the player listed is not a Connected Player of the current player or if the player does not provide permission to enter the new context. Otherwise, the promise will resolve when the game has switched into the new context. Parameters playerID string ID of the player Examples console.log(FBInstant.context.getID());// 1122334455FBInstant.context .createAsync('12345678') .then(function() { console.log(FBInstant.context.getID()); // 5544332211 }); Throws INVALID_PARAM Throws SAME_CONTEXT Throws NETWORK_FAILURE Throws USER_INPUT Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves when the game has switched into the new context, or rejects otherwise.

getPlayersAsync( ) Gets an array of #contextplayer objects containing information about active players (people who played the game in the last 90 days) that are associated with the current context. This may include the current player. Examples var contextPlayers = FBInstant.context.getPlayersAsync() .then(function(players) { console.log(players.map(function(player) { return { id: player.getID(), name: player.getName(), } })); });// [{id: '123456789', name: 'Luke'}, {id: '987654321', name: 'Leia'}] Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Throws INVALID_OPERATION Returns Promise<Array>

payments [IN CLOSED BETA] Contains functions and properties related to payments and purchases of game products.

getCatalogAsync( ) Fetches the game's product catalog. Examples FBInstant.payments.getCatalogAsync().then(function (catalog) { console.log(catalog); // [{productID: '12345', ...}, ...]}); Throws CLIENT_UNSUPPORTED_OPERATION Throws PAYMENTS_NOT_INITIALIZED Throws NETWORK_FAILURE Returns Promise<Array> The set of products that are registered to the game.

purchaseAsync( ) Begins the purchase flow for a specific product. Will immediately reject if called before FBInstant.startGameAsync() has resolved. Parameters purchaseConfig PurchaseConfig The purchase's configuration details. Examples FBInstant.payments.purchaseAsync({ productID: '12345', developerPayload: 'foobar',}).then(function (purchase) { console.log(purchase); // {productID: '12345', purchaseToken: '54321', developerPayload: 'foobar', ...}}); Throws CLIENT_UNSUPPORTED_OPERATION Throws PAYMENTS_NOT_INITIALIZED Throws INVALID_PARAM Throws NETWORK_FAILURE Throws INVALID_OPERATION Returns Promise A Promise that resolves when the product is successfully purchased by the player. Otherwise, it rejects.

getPurchasesAsync( ) Fetches all of the player's unconsumed purchases. As a best practice, the game should fetch the current player's purchases as soon as the client indicates that it is ready to perform payments-related operations. The game can then process and consume any purchases that are waiting to be consumed. Examples FBInstant.payments.getPurchasesAsync().then(function (purchases) { console.log(purchase); // [{productID: '12345', ...}, ...]}); Throws CLIENT_UNSUPPORTED_OPERATION Throws PAYMENTS_NOT_INITIALIZED Throws NETWORK_FAILURE Returns Promise<Array> The set of purchases that the player has made for the game.

consumePurchaseAsync( ) Consumes a specific purchase belonging to the current player. Before provisioning a product's effects to the player, the game should request the consumption of the purchased product. Once the purchase is successfully consumed, the game should immediately provide the player with the effects of their purchase. Parameters purchaseToken string The purchase token of the purchase that should be consumed. Examples FBInstant.payments.consumePurchaseAsync('54321').then(function () { // Purchase successfully consumed! // Game should now provision the product to the player}); Throws CLIENT_UNSUPPORTED_OPERATION Throws PAYMENTS_NOT_INITIALIZED Throws INVALID_PARAM Throws NETWORK_FAILURE Returns Promise A Promise that resolves when the purchase has been consumed successfully.

onReady( ) Sets a callback to be triggered when Payments operations are available. Parameters callback Function The callback function to be executed when Payments are available. Examples FBInstant.payments.onReady(function () { console.log('Payments Ready!')}); Returns void

getLocale( ) The current locale. See origincache.facebook.com/developers/… for a complete list of supported locale values. Use this to determine what languages the current game should be localized with. The value will not be accurate until FBInstant.startGameAsync() resolves. Examples // This function should be called after FBInstant.startGameAsync()// resolves.var locale = FBInstant.getLocale(); // 'en_US' Returns string? The current locale.

getPlatform( ) The platform on which the game is currently running. The value will always be null until FBInstant.initializeAsync() resolves. Examples // This function should be called after FBInstant.initializeAsync()// resolves.var platform = FBInstant.getPlatform(); // 'IOS' Returns Platform?

getSDKVersion( ) The string representation of this SDK version. Examples // This function should be called after FBInstant.initializeAsync()// resolves.var sdkVersion = FBInstant.getSDKVersion(); // '2.0' Returns string The SDK version.

initializeAsync( ) Initializes the SDK library. This should be called before any other SDK functions. Examples FBInstant.initializeAsync().then(function() { // Many properties will be null until the initialization completes. // This is a good place to fetch them: var locale = FBInstant.getLocale(); // 'en_US' var platform = FBInstant.getPlatform(); // 'IOS' var sdkVersion = FBInstant.getSDKVersion(); // '3.0' var playerID = FBInstant.player.getID();}); Throws INVALID_OPERATION Returns Promise A promise that resolves when the SDK is ready to use.

setLoadingProgress( ) Report the game's initial loading progress. Parameters percentage number A number between 0 and 100. Examples FBInstant.setLoadingProgress(50); // Assets are 50% loaded Returns void

getSupportedAPIs( ) Provides a list of API functions that are supported by the client. Examples // This function should be called after FBInstant.initializeAsync()// resolves.FBInstant.getSupportedAPIs();// ['getLocale', 'initializeAsync', 'player.getID', 'context.getType', ...] Returns Array List of API functions that the client explicitly supports.

getEntryPointData( ) Returns any data object associated with the entry point that the game was launched from. The contents of the object are developer-defined, and can occur from entry points on different platforms. This will return null for older mobile clients, as well as when there is no data associated with the particular entry point. This function should be called after FBInstant.startGameAsync() resolves. Examples // This function should be called after FBInstant.startGameAsync()// resolves.const entryPointData = FBInstant.getEntryPointData(); Returns Object? Data associated with the current entry point.

getEntryPointAsync( ) Returns the entry point that the game was launched from. This function should not be called until FBInstant.startGameAsync has resolved. Examples // This function should be called after FBInstant.startGameAsync()// resolves.FBInstant.getEntryPointAsync().then(entrypoint => console.log(entrypoint));// 'admin_message' Returns string The name of the entry point from which the user started the game

setSessionData( ) Sets the data associated with the individual gameplay session for the current context. This function should be called whenever the game would like to update the current session data. This session data may be used to populate a variety of payloads, such as game play webhooks. Parameters sessionData Object An arbitrary data object, which must be less than or equal to 1000 characters when stringified. Examples FBInstant.setSessionData({coinsEarned: 10, eventsSeen: ['start', ...]}); Returns void

startGameAsync( ) This indicates that the game has finished initial loading and is ready to start. Context information will be up-to-date when the returned promise resolves. Examples FBInstant.startGameAsync().then(function() { myGame.start();}); Throws INVALID_PARAM Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves when the game should start.

shareAsync( ) This invokes a dialog to let the user share specified content, either as a message in Messenger or as a post on the user's timeline. A blob of data can be attached to the share which every game session launched from the share will be able to access from FBInstant.getEntryPointData(). This data must be less than or equal to 1000 characters when stringified. The user may choose to cancel the share action and close the dialog, and the returned promise will resolve when the dialog is closed regardless if the user actually shared the content or not. Parameters payload SharePayload Specify what to share. See example for details. Examples FBInstant.shareAsync({ intent: 'REQUEST', image: base64Picture, text: 'X is asking for your help!', data: { myReplayData: '...' },}).then(function() { // continue with the game.}); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Throws INVALID_OPERATION Returns Promise A promise that resolves when the share is completed or cancelled.

updateAsync( ) Informs Facebook of an update that occurred in the game. This will temporarily yield control to Facebook and Facebook will decide what to do based on what the update is. The returned promise will resolve/reject when Facebook returns control to the game. Parameters payload UpdatePayload A payload that describes the update. Examples // This will post a custom update. If the game is played in a messenger// chat thread, this will post a message into the thread with the specified// image and text message. And when people launch the game from this// message, those game sessions will be able to access the specified blob// of data through FBInstant.getEntryPointData().FBInstant.updateAsync({ action: 'CUSTOM', cta: 'Join The Fight', image: base64Picture, text: { default: 'X just invaded Y's village!', localizations: { ar_AR: 'X \u0641\u0642\u0637 \u063A\u0632\u062A ' + '\u0642\u0631\u064A\u0629 Y!', en_US: 'X just invaded Y's village!', es_LA: '\u00A1X acaba de invadir el pueblo de Y!', } } template: 'VILLAGE_INVASION', data: { myReplayData: '...' }, strategy: 'IMMEDIATE', notification: 'NO_PUSH',}).then(function() { // closes the game after the update is posted. FBInstant.quit();}); Throws INVALID_PARAM Throws PENDING_REQUEST Throws INVALID_OPERATION Returns Promise A promise that resolves when Facebook gives control back to the game.

switchGameAsync( ) Request that the client switch to a different Instant Game. The API will reject if the switch fails - else, the client will load the new game. Parameters appID string The Application ID of the Instant Game to switch to. The application must be an Instant Game, and must belong to the same business as the current game. To associate different games with the same business, you can use Business Manager: developers.facebook.com/docs/apps/b…. data Object? An optional data payload. This will be set as the entrypoint data for the game being switched to. Must be less than or equal to 1000 characters when stringified. Examples FBInstant.switchGameAsync('12345678').catch(function (e) { // Handle game change failure}); Throws USER_INPUT Throws INVALID_PARAM Throws PENDING_REQUEST Throws CLIENT_REQUIRES_UPDATE Returns Promise

canCreateShortcutAsync( ) Returns whether or not the user is eligible to have shortcut creation requested. Will return false if createShortcutAsync was already called this session or the user is ineligible for shortcut creation. Examples FBInstant.canCreateShortcutAsync() .then(function(canCreateShortcut) { if (canCreateShortcut) { FBInstant.createShortcutAsync() .then(function() { // Shortcut created }) .catch(function() { // Shortcut not created }); } }); Throws PENDING_REQUEST Throws CLIENT_REQUIRES_UPDATE Throws INVALID_OPERATION Returns Promise Promise that resolves with true if the game can request the player create a shortcut to the game, and false otherwise

createShortcutAsync( ) Prompts the user to create a shortcut to the game if they are eligible to Can only be called once per session. (see canCreateShortcutAsync) Examples FBInstant.canCreateShortcutAsync() .then(function(canCreateShortcut) { if (canCreateShortcut) { FBInstant.createShortcutAsync() .then(function() { // Shortcut created }) .catch(function() { // Shortcut not created }); } }); Throws USER_INPUT Throws PENDING_REQUEST Throws CLIENT_REQUIRES_UPDATE Throws INVALID_OPERATION Returns Promise

quit( ) Quits the game. Examples FBInstant.quit(); Returns void

logEvent( ) Log an app event with FB Analytics. See developers.facebook.com/docs/javasc… for more details about FB Analytics. Parameters eventName string Name of the event. Must be 2 to 40 characters, and can only contain '', '-', ' ', and alphanumeric characters. valueToSum number An optional numeric value that FB Analytics can calculate a sum with. parameters Object An optional object that can contain up to 25 key-value pairs to be logged with the event. Keys must be 2 to 40 characters, and can only contain '', '-', ' ', and alphanumeric characters. Values must be less than 100 characters in length. Examples var logged = FBInstant.logEvent( 'my_custom_event', 42, {custom_property: 'custom_value'},); Returns APIError? The error if the event failed to log; otherwise returns null.

onPause( ) Set a callback to be fired when a pause event is triggered. Parameters func Function A function to call when a pause event occurs. Examples FBInstant.onPause(function() { console.log('Pause event was triggered!');}) Returns void

getInterstitialAdAsync( ) Attempt to create an instance of interstitial ad. This instance can then be preloaded and presented. Parameters placementID string The placement ID that's been setup in your Audience Network settings. Examples FBInstant.getInterstitialAdAsync( 'my_placement_id',).then(function(interstitial) { interstitial.getPlacementID(); // 'my_placement_id'}); Throws ADS_TOO_MANY_INSTANCES Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves with a #adinstance, or rejects with a #apierror if it couldn't be created.

getRewardedVideoAsync( ) Attempt to create an instance of rewarded video. This instance can then be preloaded and presented. Parameters placementID string The placement ID that's been setup in your Audience Network settings. Examples FBInstant.getRewardedVideoAsync( 'my_placement_id',).then(function(rewardedVideo) { rewardedVideo.getPlacementID(); // 'my_placement_id'}); Throws ADS_TOO_MANY_INSTANCES Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves with a #adinstance, or rejects with a #apierror if it couldn't be created.

matchPlayerAsync( ) Attempts to match the current player with other users looking for people to play with. If successful, a new Messenger group thread will be created containing the matched players and the player will be context switched to that thread. The default minimum and maximum number of players in one matched thread are 2 and 20 respectively, depending on how many players are trying to get matched around the same time. The values can be changed in fbapp-config.json. See the [Bundle Config documentation]developers.facebook.com/docs/games/… for documentation about fbapp-config.json. Parameters matchTag string? Optional extra information about the player used to group them with similar players. Players will only be grouped with other players with exactly the same tag. The tag must only include letters, numbers, and underscores and be 100 characters or less in length. switchContextWhenMatched boolean Optional extra parameter that specifies whether the player should be immediately switched to the new context when a match is found. By default this will be false which will mean the player needs explicitly press play after being matched to switch to the new context. Examples FBInstant .matchPlayerAsync('level1') .then(function() { console.log(FBInstant.context.getID()); // 12345 }); FBInstant .matchPlayerAsync() .then(function() { console.log(FBInstant.context.getID()); // 3456 }); FBInstant .matchPlayerAsync(null, true) .then(function() { console.log(FBInstant.context.getID()); // 3456 }); Throws INVALID_PARAM Throws NETWORK_FAILURE Throws USER_INPUT Throws PENDING_REQUEST Throws CLIENT_UNSUPPORTED_OPERATION Throws INVALID_OPERATION Returns Promise A promise that resolves when the player has been added to a group thread and switched into the thread's context.

checkCanPlayerMatchAsync( ) Checks if the current player is eligible for the matchPlayerAsync API. Examples FBInstant .checkCanPlayerMatchAsync() .then(canMatch => { if (canMatch) { FBInstant.matchPlayerAsync('level1'); } }); Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Returns Promise A promise that resolves with true if the player is eligible to match with other players and false otherwise.

getLeaderboardAsync( ) Fetch a specific leaderboard belonging to this Instant Game. Parameters name string The name of the leaderboard. Each leaderboard for an Instant Game must have its own distinct name. Examples FBInstant.getLeaderboardAsync('my_awesome_leaderboard') .then(leaderboard => { console.log(leaderboard.getName()); // 'my_awesome_leaderboard' }); Throws LEADERBOARD_NOT_FOUND Throws NETWORK_FAILURE Throws CLIENT_UNSUPPORTED_OPERATION Throws INVALID_OPERATION Throws INVALID_PARAM Returns Promise A promise that resolves with the matching leaderboard, rejecting if one is not found.

LocalizationsDict Represents a mapping from locales to translations of a given string. Each property is an optional five-character Facebook locale code of the form xx_XX. See origincache.facebook.com/developers/… for a complete list of supported locale codes. Type: Object

APIError An API Error returned by the Instant Games SDK

code The relevant error code Type: ErrorCodeType

message A message describing the error Type: string

SignedPlayerInfo Represents information about the player along with a signature to verify that it indeed comes from Facebook.

getPlayerID( ) Get the id of the player. Examples FBInstant.player.getSignedPlayerInfoAsync() .then(function (result) { result.getPlayerID(); // same value as FBInstant.player.getID() }); Returns string The ID of the player

getSignature( ) A signature to verify this object indeed comes from Facebook. The string is base64url encoded and signed with an HMAC version of your App Secret, based on the OAuth 2.0 spec. You can validate it with the following 4 steps: Split the signature into two parts delimited by the '.' character. Decode the first part (the encoded signature) with base64url encoding. Decode the second part (the response payload) with base64url encoding, which should be a string representation of a JSON object that has the following fields: ** algorithm - always equals to HMAC-SHA256 ** issued_at - a unix timestamp of when this response was issued. ** player_id - unique identifier of the player. ** request_payload - the requestPayload string you specified when calling FBInstant.player.getSignedPlayerInfoAsync. Hash the whole response payload string using HMAC SHA-256 and your app secret and confirm that it is equal to the encoded signature. You may also wish to validate the issued_at timestamp in the response payload to ensure the request was made recently. Signature validation should only happen on your server. Never do it on the client side as it will compromise your app secret key. Examples FBInstant.player.getSignedPlayerInfoAsync() .then(function (result) { result.getSignature(); // Eii6e636mz5J47sfqAYEK40jYAwoFqi3x5bxHkPG4Q4.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUwMDM5ODY3NSwicGxheWVyX2lkIjoiMTI0OTUyNTMwMTc1MjIwMSIsInJlcXVlc3RfcGF5bG9hZCI6Im15X2ZpcnN0X3JlcXVlc3QifQ }); Returns string The signature string.

ConnectedPlayer Represents information about a player who is connected to the current player.

getID( ) Get the id of the connected player. Returns string The ID of the connected player

getName( ) Get the player's full name. Returns string? The player's full name

getPhoto( ) Get the player's public profile photo. Returns string? A url to the player's public profile photo

ContextPlayer Represents information about a player who is in the context that the current player is playing in.

getID( ) Get the id of the context player. Returns string The ID of the context player

getName( ) Get the player's localized display name. Returns string? The player's localized display name.

getPhoto( ) Get the player's public profile photo. Returns string? A url to the player's public profile photo

AdInstance Represents an instance of an ad.

getPlacementID( ) Return the Audience Network placement ID of this ad instance.

loadAsync( ) Preload the ad. The returned promise resolves when the preload completes, and rejects if it failed. Examples FBInstant.getInterstitialAdAsync( 'my_placement_id',).then(function(interstitial) { return interstitial.loadAsync();}).then(function() { // Ad loaded}); Throws ADS_FREQUENT_LOAD Throws ADS_NO_FILL Throws INVALID_PARAM Throws NETWORK_FAILURE Returns Promise

showAsync( ) Present the ad. The returned promise resolves when user finished watching the ad, and rejects if it failed to present or was closed during the ad. Examples var ad = null;FBInstant.getRewardedVideoAsync( 'my_placement_id',).then(function(rewardedVideo) { ad = rewardedVideo; return ad.loadAsync();}).then(function() { // Ad loaded return ad.showAsync();}).then(function() { // Ad watched}); Throws ADS_NOT_LOADED Throws INVALID_PARAM Throws NETWORK_FAILURE Throws INVALID_OPERATION Returns Promise

Product Represents a game's product information. Type: Object Properties title string The title of the product productID string The product's game-specified identifier description string? The product description imageURI string? A link to the product's associated image price string The price of the product priceCurrencyCode string The currency code for the product

ContextFilter A filter that may be applied to a Context Choose operation 'NEW_CONTEXT_ONLY' - Prefer to only surface contexts the game has not been played in before. 'INCLUDE_EXISTING_CHALLENGES' - Include the "Existing Challenges" section, which surfaces actively played-in contexts that the player is a part of. 'NEW_PLAYERS_ONLY' - In sections containing individuals, prefer people who have not played the game. Type: ("NEW_CONTEXT_ONLY" | "INCLUDE_EXISTING_CHALLENGES" | "NEW_PLAYERS_ONLY")

Platform Represents the current platform that the user is playing on. Type: ("IOS" | "ANDROID" | "WEB" | "MOBILE_WEB")

ContextSizeResponse The answer field is true if the current context size is between the minSize and maxSize values that are specified in the object, and false otherwise. Type: {answer: boolean, minSize: number?, maxSize: number?}

Purchase Represents an individual purchase of a game product. Type: Object Properties developerPayload string? A developer-specified string, provided during the purchase of the product paymentID string The identifier for the purchase transaction productID string The product's game-specified identifier purchaseTime string Unix timestamp of when the purchase occurred purchaseToken string A token representing the purchase that may be used to consume the purchase signedRequest SignedPurchaseRequest Server-signed encoding of the purchase request

Leaderboard An Instant Game leaderboard

getName( ) The name of the leaderboard. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { console.log(leaderboard.getName()); // my_leaderboard }); Returns string

getContextID( ) The ID of the context that the leaderboard is associated with, or null if the leaderboard is not tied to a particular context. Examples FBInstant.getLeaderboardAsync('contextual_leaderboard') .then(function(leaderboard) { console.log(leaderboard.getContextID()); // 12345678 }); FBInstant.getLeaderboardAsync('global_leaderboard') .then(function(leaderboard) { console.log(leaderboard.getContextID()); // null }); Returns string?

getEntryCountAsync( ) Fetches the total number of player entries in the leaderboard. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getEntryCountAsync(); }) .then(function(count) { console.log(count); }); // 24 Throws NETWORK_FAILURE Throws RATE_LIMITED Returns Promise A unique identifier for the player.

setScoreAsync( ) Updates the player's score. If the player has an existing score, the old score will only be replaced if the new score is better than it. NOTE: If the leaderboard is associated with a specific context, the game must be in that context to set a score for the player. Parameters score number The new score for the player. Must be a 64-bit integer number. extraData string?= // 2 Metadata to associate with the stored score. Must be less than 2KB in size. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.setScoreAsync(42, '{race: "elf", level: 3}'); }) .then(function(entry) { console.log(entry.getScore()); // 42 console.log(entry.getExtraData()); // '{race: "elf", level: 3}' }); Throws LEADERBOARD_WRONG_CONTEXT Throws NETWORK_FAILURE Throws INVALID_PARAM Throws INVALID_OPERATION Throws RATE_LIMITED Returns Promise Resolves with the current leaderboard entry for the player after the update.

getPlayerEntryAsync( ) Retrieves the leaderboard's entry for the current player, or null if the player has not set one yet. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getPlayerEntryAsync(); }) .then(function(entry) { console.log(entry.getRank()); // 2 console.log(entry.getScore()); // 42 console.log(entry.getExtraData()); // '{race: "elf", level: 3}' }); Throws NETWORK_FAILURE Throws INVALID_OPERATION Throws RATE_LIMITED Returns Promise? Resolves with the current leaderboard entry for the player.

getEntriesAsync( ) Retrieves a set of leaderboard entries, ordered by score ranking in the leaderboard. Parameters count number The number of entries to attempt to fetch from the leaderboard. Defaults to 10 if not specified. Currently, up to a maximum of 100 entries may be fetched per query. offset number The offset from the top of the leaderboard that entries will be fetched from. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getEntriesAsync(); }) .then(function(entries) { console.log(entries.length); // 10 console.log(entries[0].getRank()); // 1 console.log(entries[0].getScore()); // 42 console.log(entries[1].getRank()); // 2 console.log(entries[1].getScore()); // 40 }); FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getEntriesAsync(5, 3); }) .then(function(entries) { console.log(entries.length); // 5 console.log(entries[0].getRank()); // 4 console.log(entries[0].getScore()); // 34 console.log(entries[1].getRank()); // 5 console.log(entries[1].getScore()); // 31 }); Throws NETWORK_FAILURE Throws RATE_LIMITED Returns Promise<Array> Resolves with the leaderboard entries that match the query.

getConnectedPlayerEntriesAsync( ) Retrieves the leaderboard score entries of the current player's connected players (including the current player), ordered by local rank within the set of connected players. Parameters count number The number of entries to attempt to fetch from the leaderboard. Defaults to 10 if not specified. Currently, up to a maximum of 100 entries may be fetched per query. offset number The offset from the set of ordered connected player score entries to fetch from. Examples FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getConnectedPlayerEntriesAsync(); }) .then(function(entries) { console.log(entries.length); // 10 console.log(entries[0].getRank()); // 1 console.log(entries[0].getScore()); // 42 console.log(entries[1].getRank()); // 2 console.log(entries[1].getScore()); // 40 }); FBInstant.getLeaderboardAsync('my_leaderboard') .then(function(leaderboard) { return leaderboard.getConnectedPlayerEntriesAsync(5, 3); }) .then(function(entries) { console.log(entries.length); // 5 console.log(entries[0].getRank()); // 4 console.log(entries[0].getScore()); // 34 console.log(entries[1].getRank()); // 5 console.log(entries[1].getScore()); // 31 }); Throws NETWORK_FAILURE Throws RATE_LIMITED Returns Promise<Array> Resolves with the leaderboard entries that match the query.

SharePayload Represents content to be shared by the user. Type: Object Properties intent ("INVITE" | "REQUEST" | "CHALLENGE" | "SHARE") Indicates the intent of the share. image string A base64 encoded image to be shared. text string A text message to be shared. data Object? A blob of data to attach to the share. All game sessions launched from the share will be able to access this blob through FBInstant.getEntryPointData().

UpdateAction Represents the type of the update action to perform. Properties CUSTOM string A custom update, with all content specified by the game. LEADERBOARD string An update associated with an Instant Game leaderboard.

ErrorCode Error codes that may be returned by the Instant Games API Properties ADS_FREQUENT_LOAD string Ads are being loaded too frequently. ADS_NO_FILL string We were not able to serve ads to the current user. This can happen if the user has opted out of interest-based ads on their device, or if we do not have ad inventory to show for that user. ADS_NOT_LOADED string Attempted to show an ad that has not been loaded successfully. ADS_TOO_MANY_INSTANCES string There are too many concurrent ad instances. Load and show existing ad instances before creating new ones. ANALYTICS_POST_EXCEPTION string The analytics API experienced a problem while attempting to post an event. CLIENT_REQUIRES_UPDATE string [Deprecated] - The client requires an update to access the feature that returned this result. If this result is returned on web, it means the feature is not supported by the web client yet. Deprecated in favor of CLIENT_UNSUPPORTED_OPERATION in v5.0 and above CLIENT_UNSUPPORTED_OPERATION string The client does not support the current operation. This may be due to lack of support on the client version or platform, or because the operation is not allowed for the game or player. INVALID_OPERATION string The requested operation is invalid or the current game state. This may include requests that violate limitations, such as exceeding storage thresholds, or are not available in a certain state, such as making a context-specific request in a solo context. INVALID_PARAM string The parameter(s) passed to the API are invalid. Could indicate an incorrect type, invalid number of arguments, or a semantic issue (for example, passing an unserializable object to a serializing function). LEADERBOARD_NOT_FOUND string No leaderboard with the requested name was found. Either the leaderboard does not exist yet, or the name did not match any registered leaderboard configuration for the game. LEADERBOARD_WRONG_CONTEXT string Attempted to write to a leaderboard that's associated with a context other than the one the game is currently being played in. NETWORK_FAILURE string The client experienced an issue with a network request. This is likely due to a transient issue, such as the player's internet connection dropping. PAYMENTS_NOT_INITIALIZED string The client has not completed setting up payments or is not accepting payments API calls. PENDING_REQUEST string Represents a rejection due an existing request that conflicts with this one. For example, we will reject any calls that would surface a Facebook UI when another request that depends on a Facebook UI is pending. RATE_LIMITED string Some APIs or operations are being called too often. This is likely due to the game calling a particular API an excessive amount of times in a very short period. Reducing the rate of requests should cause this error to go away. SAME_CONTEXT string The game attempted to perform a context switch into the current context. UNKNOWN string An unknown or unspecified issue occurred. This is the default error code returned when the client does not specify a code. USER_INPUT string The user made a choice that resulted in a rejection. For example, if the game calls up the Context Switch dialog and the player closes it, this error code will be included in the promise rejection. Examples FBInstant.startGameAsync().catch(function(e) { console.log(e);});// {code: 'CLIENT_UNSUPPORTED_OPERATION', message: '...'}

ErrorCodeType An Instant Games error code, one of #errorcode Type: string

SignedPurchaseRequest Type: string Examples Eii6e636mz5J47sfqAYEK40jYAwoFqi3x5bxHkPG4Q4.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUwMDM5ODY3NSwicGxheWVyX2lkIjoiMTI0OTUyNTMwMTc1MjIwMSIsInJlcXVlc3RfcGF5bG9hZCI6Im15X2ZpcnN0X3JlcXVlc3QifQ

PurchaseConfig The configuration of a purchase request for a product registered to the game. Type: Object Properties productID string The identifier of the product to purchase developerPayload string? An optional developer-specified payload, to be included in the returned purchase's signed request.

CustomUpdatePayload Represents a custom update for FBInstant.updateAsync. Note that if localized content is not provided, a Facebook supplied localized string will be used for the call to action and text. The default string should always be in English. Type: Object Properties action UpdateAction For custom updates, this should be 'CUSTOM'. template string ID of the template this custom update is using. Templates should be predefined in fbapp-config.json. See the [Bundle Config documentation]developers.facebook.com/docs/games/… for documentation about fbapp-config.json. cta (string? | LocalizableContent?) Optional call-to-action button text. By default we will use a localized 'Play' as the button text. To provide localized versions of your own call to action, pass an object with the default cta as the value of 'default' and another object mapping locale keys to translations as the value of 'localizations'. image string Data URL of a base64 encoded image. text (string | LocalizableContent) A text message, or an object with the default text as the value of 'default' and another object mapping locale keys to translations as the value of 'localizations'. data Object? A blob of data to attach to the update. All game sessions launched from the update will be able to access this blob through FBInstant.getEntryPointData(). Must be less than or equal to 1000 characters when stringified. strategy string? Specifies how the update should be delivered. This can be one of the following: 'IMMEDIATE' - The update should be posted immediately. 'LAST' - The update should be posted when the game session ends. The most recent update sent using the 'LAST' strategy will be the one sent. 'IMMEDIATE_CLEAR' - The update is posted immediately, and clears any other pending updates (such as those sent with the 'LAST' strategy). If no strategy is specified, we default to 'IMMEDIATE'. notification string? Specifies notification setting for the custom update. This can be 'NO_PUSH' or 'PUSH', and defaults to 'NO_PUSH'. Use push notification only for updates that are high-signal and immediately actionable for the recipients. Also note that push notification is not always guaranteed, depending on user setting and platform policies.

LeaderboardUpdatePayload Represents a leaderboard update for FBInstant.updateAsync. Type: Object Properties action UpdateAction For a leaderboard update, this should be 'LEADERBOARD'. text. By default we will use a localized 'Play Now' as the button text. name string The name of the leaderboard to feature in the update. text string? Optional text message. If not specified, a localized fallback message will be provided instead.

LocalizableContent Represents a string with localizations and a default value to fall back on. Type: Object Properties default string The default value of the string to use if the viewer's locale is not a key in the localizations object. localizations LocalizationsDict Specifies what string to use for viewers in each locale. See origincache.facebook.com/developers/… for a complete list of supported locale values.

LeaderboardEntry A score entry for an Instant Game leaderboard

getScore( ) Gets the score associated with the entry. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getScore()); // 9001 }); Returns number Returns an integer score value.

getFormattedScore( ) Gets the score associated with the entry, formatted with the score format associated with the leaderboard. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getFormattedScore()); // '90.01 meters' }); Returns string Returns a formatted score.

getTimestamp( ) Gets the timestamp of when the leaderboard entry was last updated. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getTimestamp()); // 1515806355 }); Returns number Returns a Unix timestamp.

getRank( ) Gets the rank of the player's score in the leaderboard. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getRank()); // 2 }); Returns number Returns the entry's leaderboard ranking.

getExtraData( ) Gets the developer-specified payload associated with the score, or null if one was not set. Examples leaderboard.setScoreAsync(42, '{race: "elf", level: 3}'); .then(function(entry) { console.log(entry.getExtraData()); // '{race: "elf", level: 3}' }); Returns string? An optional developer-specified payload associated with the score.

getPlayer( ) Gets information about the player associated with the entry. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getPlayer().getName()); // Sally }); Returns LeaderboardPlayer

LeaderboardPlayer Details about the player associated with a score entry.

getName( ) Gets the player's localized display name. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getPlayer().getName()); // Sally }); Returns string The player's localized display name.

getPhoto( ) Returns a url to the player's public profile photo. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getPlayer().getPhoto()); // <photo_url> }); Returns string? Url to the player's public profile photo.

getID( ) Gets the game's unique identifier for the player. Examples leaderboard.setScoreAsync(9001) .then(function(entry) { console.log(entry.getPlayer().getID()); // 12345678 }); Returns string? The game-scoped identifier for the player

相關文章