我正在尝试使用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 Reference 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的resolve函数中调用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);
});
});