Skip to content

Instantly share code, notes, and snippets.

@letswritetw
Created February 8, 2021 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letswritetw/d04598b9191156b2cab767e299caa5a4 to your computer and use it in GitHub Desktop.
Save letswritetw/d04598b9191156b2cab767e299caa5a4 to your computer and use it in GitHub Desktop.
ig-oembed
<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