Created
February 8, 2021 12:52
-
-
Save letswritetw/d04598b9191156b2cab767e299caa5a4 to your computer and use it in GitHub Desktop.
ig-oembed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="ig-iframe"></div> | |
<script src="https://www.instagram.com/embed.js"></script> | |
<script> | |
const getToken = '部署完取得的網址'; | |
const igUri = 'IG 貼文的網址'; | |
const hideCaption = true; // 選填,要不要隱藏描述,true 隱藏、false 不隱藏,預設為 false | |
const maxWidth = 400; // 選填,貼文的最大寬度是多少 | |
fetch(getToken) | |
.then(res => res.json()) | |
.then(res => { | |
const token = res.access_token; | |
fetch(`https://graph.facebook.com/v9.0/instagram_oembed?url=${igUri}&access_token=${token}&hidecaption=${hideCaption}&maxwidth=${maxWidth}`) | |
.then(res => res.json()) | |
.then(res => { | |
const wrap = document.getElementById('ig-iframe'); | |
wrap.insertAdjacentHTML('afterbegin', res.html); | |
instgrm.Embeds.process(); | |
}).catch(err => { | |
throw Error(e) | |
}) | |
}).catch(err => { | |
throw Error(e) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment