我有一个 javascript 函数,可以加载 Instagram 帖子的 HTML 嵌入代码。帖子出现,但照片被灰色背景和 Instagram 标志取代。该帖子确实包含其他信息,例如主题标签、发布时间和用户名。我认为问题在于 Instagram embeds.js JavaScript 库未正确加载。我知道我可以手动执行此操作,但在我的代码中的语法和位置方面很难做到这一点。下面是我的代码。
<script type="text/javascript">
var auto_refresh = setInterval(
(function () {
$("#latestData").load("displayPost.php");//displayPost.php "echo" html embed code
}), 10000);
</script>
<div id="latestData"></div>
<script src="https://platform.instagram.com/en_US/embeds.js"></script>
<script>if ( typeof window.instgrm !== 'undefined' ) {
window.instgrm.Embeds.process();
}</script>
我已经使用这些来尝试解决这个问题。
最佳答案
发生这种情况是因为您没有正确构建执行顺序。您应该首先加载您的嵌入代码,然后在回调中调用instgrm.Embeds.process()
。通过将 OMITSCRIPT=true
附加到您的嵌入 URL,确保您没有在每个嵌入中包含 embeds.js。相反,在页面的脚本标记中包含 embeds.js 一次。
关于javascript - Instagram embeds.js 库未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32366979/