Skip to content

Commit 2880ab1

Browse files
fix(Instagram): Update Instagram oEmbed endpoint (#148)
BREAKING CHANGE: You'll now need to pass a required `accessToken` option whenever you're using the Instagram service. Check out the Instagram oEmbed access token docs and requirements to know how to get this.
1 parent 4247d4c commit 2880ab1

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,39 @@ https://instagram.com/p/B60jPE6J8U-
382382

383383
</details>
384384

385+
#### Options
386+
387+
All options should go under the `Instagram` namespace.
388+
389+
| name | Type | Required | Default | Description |
390+
| ----------- | -------- | -------- | ------- | -------------------------------------------------------- |
391+
| accessToken | `string` || | An App Access Token (recommended) or Client Access Token |
392+
393+
##### accessToken
394+
395+
To get an App Access Token (recommended) or Client Access Token for the
396+
Instagram embed, check out the [Instagram oEmbed access token
397+
docs][instagram-oembed-access-token-docs] and
398+
[requirements][instagram-oembed-requirements-docs].
399+
400+
The safest way to enter your `accessToken` is to set is as an [environment
401+
variable][gatsby-environment-variables-docs].
402+
403+
<details>
404+
<summary><b>Example</b></summary>
405+
406+
```js
407+
const GatsbyRemarkEmbedderOptions = {
408+
services: {
409+
Instagram: {
410+
accessToken: env.process.INSTAGRAM_ACCESS_TOKEN,
411+
},
412+
},
413+
};
414+
```
415+
416+
</details>
417+
385418
### Lichess
386419

387420
#### Usage
@@ -863,6 +896,7 @@ MIT
863896
[codesandbox]: https://codesandbox.io
864897
[embedded-tweet-docs]: https://developer.twitter.com/web/embedded-tweets
865898
[gatsby]: https://github.com/gatsbyjs/gatsby
899+
[gatsby-environment-variables-docs]: https://www.gatsbyjs.com/docs/environment-variables
866900
[gatsby-https-docs]: https://gatsbyjs.org/docs/local-https
867901
[gatsby-plugin-instagram-embed]: https://github.com/MichaelDeBoey/gatsby-plugin-instagram-embed
868902
[gatsby-plugin-mdx]: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx
@@ -871,6 +905,8 @@ MIT
871905
[gatsby-transformer-remark]: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-remark
872906
[giphy]: https://giphy.com
873907
[instagram]: https://instagram.com
908+
[instagram-oembed-access-token-docs]: https://developers.facebook.com/docs/instagram/oembed#access-tokens
909+
[instagram-oembed-requirements-docs]: https://developers.facebook.com/docs/instagram/oembed#requirements
874910
[kentcdodds.com-repo]: https://github.com/kentcdodds/kentcdodds.com
875911
[lichess]: https://lichess.org
876912
[netlify-environment-variables-docs]: https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata

src/__tests__/plugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('gatsby-remark-embedder', () => {
2727
{ cache, markdownAST },
2828
{
2929
services: {
30+
Instagram: {
31+
accessToken: 'access-token',
32+
},
3033
Twitch: {
3134
parent: 'embed.example.com',
3235
},

src/__tests__/transformers/Instagram.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ test('Gets the correct Instagram iframe', async () => {
104104
`<blockquote class="instagram-media-mocked-fetch-transformer"><div><a href="https://instagram.com/p/B60jPE6J8U-"><p>example</p></a><p>A post shared by <a href="https://instagram.com/michaeldeboey">Michaël De Boey</a> (@michaeldeboey) on<timedatetime="2020-01-02T14:45:30+00:00">Jan 2, 2020 at 6:45am PST</time></p></div></blockquote>`
105105
);
106106

107-
const html = await getHTML('https://instagram.com/p/B60jPE6J8U-');
107+
const html = await getHTML('https://instagram.com/p/B60jPE6J8U-', {
108+
accessToken: 'access-token',
109+
});
108110

109111
expect(html).toMatchInlineSnapshot(
110112
`"<blockquote class=\\"instagram-media-mocked-fetch-transformer\\"><div><a href=\\"https://instagram.com/p/B60jPE6J8U-\\"><p>example</p></a><p>A post shared by <a href=\\"https://instagram.com/michaeldeboey\\">Michaël De Boey</a> (@michaeldeboey) on<timedatetime=\\"2020-01-02T14:45:30+00:00\\">Jan 2, 2020 at 6:45am PST</time></p></div></blockquote>"`
@@ -117,7 +119,16 @@ test('Plugin can transform Instagram links', async () => {
117119
);
118120
const markdownAST = getMarkdownASTForFile('Instagram');
119121

120-
const processedAST = await plugin({ cache, markdownAST });
122+
const processedAST = await plugin(
123+
{ cache, markdownAST },
124+
{
125+
services: {
126+
Instagram: {
127+
accessToken: 'access-token',
128+
},
129+
},
130+
}
131+
);
121132

122133
expect(parseASTToMarkdown(processedAST)).toMatchInlineSnapshot(`
123134
"<https://not-an-instagram-url.com>

src/transformers/Instagram.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const shouldTransform = (url) => {
1313
);
1414
};
1515

16-
export const getHTML = (url) =>
16+
export const getHTML = (url, { accessToken }) =>
1717
fetchOEmbedData(
18-
`https://api.instagram.com/oembed?url=${url}&omitscript=true`
18+
`https://graph.facebook.com/v8.0/instagram_oembed?url=${url}&access_token=${accessToken}&omitscript=true`
1919
).then(({ html }) => html);
20+
21+
export const name = 'Instagram';

0 commit comments

Comments
 (0)