首页 > 解决方案 > 在 https 服务器上测试 Facebook 即时游戏时,网站继续以 0% 加载

问题描述

对不起我的英语不好,我做的事情(测试我的项目)就像在官方文档(https://developers.facebook.com)中一样。我用命令测试我的证书,没有错误。当我创建一个 https 服务器时,也没有错误。您可以在此处找到该项目:developers.facebook.com。

首先,我测试localhost:8080,它显示我不安全并且 https 是红色的,当项目被嵌入时,是的,这个 url 是https://www.facebook.com/embed/instantgames/YOUR_GAME_ID/player?game_url=https://localhost:8080这个网站似乎无法工作,它继续以 0% 的速度加载。我不知道为什么。有人可以帮我吗?谢谢你的帮助!

标签: facebooktypescript

解决方案


您必须实际通知 API 您已完成加载。可以在此页面上找到最低代码,如下所示:

<script src="https://connect.facebook.net/en_US/fbinstant.6.2.js"></script>
<script>
FBInstant.initializeAsync()
  .then(function() {        

  });

// Once all assets are loaded, tells the SDK 
// to end loading view and start the game
FBInstant.startGameAsync()
  .then(function() {
    // Retrieving context and player information can only be done
    // once startGameAsync() resolves
    var contextId = FBInstant.context.getID();
    var contextType = FBInstant.context.getType();

    var playerName = FBInstant.player.getName();
    var playerPic = FBInstant.player.getPhoto();
    var playerId = FBInstant.player.getID();

    // Once startGameAsync() resolves it also means the loading view has 
    // been removed and the user can see the game viewport

    game.start();
  });
</script>

推荐阅读