簡體   English   中英

為什么FBInstant.chooseAsync方法沒有將游戲請求發送給朋友?

[英]Why FBInstant.chooseAsync method not sending game play request to friend?

我正在嘗試使用FBinstant.chooseAsync方法將游戲請求發送到我的Facebook朋友。 但是沒有請求發送給我的朋友,並且在調用此方法后,我在回調時沒有任何數據。

這是我的游戲代碼-

 FBInstant.initializeAsync() .then(function() { 


    console.log("FBInstant.initializeAsync complete"); 


    console.log("FBInstant.startGameAsync complete"); 
    FBInstant.startGameAsync().then(function() { 

        console.log("FBInstant.startGameAsync complete"); 
        console.log("FBInstant.startGameAsync context : " + FBInstant.context.getID()); 

        FBInstant.context.chooseAsync() .then(function (e) { 

            console.log("FBInstant.context.chooseAsync complete"); 
            console.log(e); 
        }); 
    }); 

});

首先, FBInstant.context.chooseAsync()打開一個上下文選擇對話框(請參閱API參考v6.2 )。 第二,為什么還要兩次使用FBInstant.startGameAsync()? 試試這個代碼:

FBInstant.initializeAsync() .then(function() {

    // Start loading game assets here 
    console.log("FBInstant.initializeAsync complete"); 

    // Finished loading. Start the game 
    FBInstant.startGameAsync().then(function() { 

        console.log("FBInstant.startGameAsync complete"); 
        console.log("FBInstant.startGameAsync context : " + FBInstant.context.getID()); 

        FBInstant.context.chooseAsync() .then(function () { 
            console.log("FBInstant.context.chooseAsync complete");
        }); 

    }); 
});

似乎您必須在choiceAsync的resolve函數中調用updateAsync,您可以嘗試以下流程:

FBInstant.context.chooseAsync() .then(function () { 
    window.FBInstant.updateAsync(
    {
      action: "CUSTOM",
      cta: "Join The Fight",
      template: "join_fight",
      image: base64Picture, //this should be source data of your share picture in 
                            //base64! you can parse your picture to base64 use  
                            //'https://www.base64-image.de'
      text: "X just invaded Y's village!",
      data: {
        myReplayData: "..."
      },
      strategy: "IMMEDIATE",
      notification: "NO_PUSH"
    }).then(function() {
      window.FBInstant.quit();
    }).catch(function(err){
        console.error(err);
    });

});

您必須添加一個方法來調用FBInstant.updateAsync()來更新上下文。 它將消息發送給上下文中選擇的朋友。

您在上下文中的每個會話只能使用一次updateAsync(即:您不能一直重復調用updateAsync方法,它只能在第一次使用,而不能在以后的請求上使用),直到您的朋友在上下文中做出響應為止。

但是,如果您更改上下文或重新打開上下文,則無論您的朋友是否響應,都可以再次發布一個更新(例如:使用提醒朋友來提醒他們響應)。

您的方法可以像這樣:

updateContext(){
var updateData = {
        action: 'CUSTOM',
        intent: 'REQUEST',
        cta: actionButton,
        template: "join_fight",
        image: "base64 image data",
        //data would be like: "data:image/png;base64,lkhkfhjvajsdbka....",
        text: 'Message to be posted',
        data: { myReplayData: 'any data to be attatched' },
        strategy: 'IMMEDIATE',
        notification: 'NO_PUSH'
    };
    FBInstant.updateAsync(updateData);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM