简体   繁体   English

Facebook 即时游戏 api 方法 canSubscribeBotAsync 方法不是 function

[英]Facebook instant games api method canSubscribeBotAsync method is not a function

So my game wants the players to have the ability to subscribe to a game bot and I'm using FBInstant.player.canSubscribeBotAsync() method.所以我的游戏希望玩家能够订阅游戏机器人,我正在使用 FBInstant.player.canSubscribeBotAsync() 方法。 But everytime, it will return an error that state但是每次都会返回一个错误 state

Uncaught TypeError: FBInstant.player.canSubscribeBotAsync is not a function here is my code未捕获的类型错误:FBInstant.player.canSubscribeBotAsync 不是 function 这是我的代码

FBInstant.player.canSubscribeBotAsync().then(function(yes){
    if(yes){
      FBInstant.player.subscribeBotAsync().then(function(){
        console.log('sub');
      }).catch(function(e)){}
    }
});

I tried using this code from FB developer doc我尝试使用 FB 开发人员文档中的此代码

FBInstant.player.canSubscribeBotAsync().then(
  can_subscribe => console.log(can_subscribe)
);

but the result still the same.但结果还是一样。

It seems that I tried to let the player subscribe when they click the button and this error appears.似乎我试图让玩家在单击按钮时订阅并出现此错误。 But when I switch it from letting the player click the subscribe button to asked when player finished loading the game, the error disappears.但是当我将它从让玩家点击订阅按钮切换到询问玩家何时完成加载游戏时,错误消失了。 The program's flow look like this程序的流程是这样的

window.onload = async () => {
      FBInstant.initializeAsync().then(()=>{
        FBInstant.startGameAsync().then((res)=>{
          FBInstant.player.canSubscribeBotAsync().then((canSub)=>{
            //Ask for sub or something
        }).catch(()=>console.log("Error"))
      })
})

But for me, this is a temporary fix since normally you should be able to call a function anywhere you want (working or not isn't my problem) and my problem is that I can only call FBInstant.player.canSubscribeBotAsync() inside FBInstant.initializeAsync() or FBInstant.startGameAsync() but not outside of them但对我来说,这是一个临时修复,因为通常你应该可以在任何你想要的地方调用 function(工作与否不是我的问题),我的问题是我只能在 FBInstant 中调用 FBInstant.player.canSubscribeBotAsync() .initializeAsync() 或 FBInstant.startGameAsync() 但不在它们之外

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM