我正试图使用FBinstant.chooseAsync方法向我的facebook firend发送游戏播放请求。但没有向我的朋友发送请求,并且在调用此方法后,我在回调时也没有得到任何数据。
这是我的游戏代码-
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");
});
});
});
似乎必须在chooseAsync的解析函数中调用updateAsync,您可以尝试类似于flow的方法:
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);
}