From f5a597a6eca8bd25c2c945145c3761f064768b25 Mon Sep 17 00:00:00 2001 From: "Zane J. Chua" Date: Mon, 17 Aug 2020 07:20:08 +0000 Subject: [PATCH 1/3] Add Highlights Support --- lib/index.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/index.js b/lib/index.js index 9060571..0f19c99 100644 --- a/lib/index.js +++ b/lib/index.js @@ -257,6 +257,50 @@ class Instagram { }) } + async getHighlightReels({ + highlightReelIds = [], + reelIds = [], + locationIds = [], + precomposedOverlay = false + } = {}) { + return this.request('/graphql/query/', { + qs: { + query_hash: '45246d3fe16ccc6577e0bd297a5db1ab', + variables: JSON.stringify({ + highlight_reel_ids: highlightReelIds, + reel_ids: reelIds, + location_ids: locationIds, + precomposed_overlay: precomposedOverlay + }) + } + }).then(data => data.data.reels_media) + } + + async getHighlightsByUsername({ username }) { + const user = await this.getUserByUsername({ username }) + return this.request('/graphql/query/', { + qs: { + query_hash: '7c16654f22c819fb63d1183034a5162f', + variables: JSON.stringify({ + user_id: user.id, + include_chaining: false, + include_reel: false, + include_suggested_users: false, + include_logged_out_extras: false, + include_highlight_reels: true + }) + } + }) + .then(data => data.data.user.edge_highlight_reels) + .then(({ edges }) => edges.map(edge => edge.node)) + } + + async getHighlightItemsByReel({ highlightReelId }) { + const reels = await this.getHighlightReels({ highlightReelIds: [highlightReelId] }) + if (reels.length === 0) return [] + return reels[0].items + } + async _getFollowData({ fieldName, queryHash, variables }) { return this.request('/graphql/query/', { qs: { From f650939de1b25a1329cf905a82d76320c3789bd2 Mon Sep 17 00:00:00 2001 From: "Zane J. Chua" Date: Wed, 2 Sep 2020 02:26:41 +0000 Subject: [PATCH 2/3] Add tests and documentation for highlights --- README.md | 25 +++++++++++++++++++++++++ helpers/index.js | 3 ++- test/index.js | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4376363..aaf60e0 100644 --- a/README.md +++ b/README.md @@ -501,6 +501,31 @@ await client.getPhotosByHashtag({ hashtag: 'unicorn' }) - `first`: A `number` of records to return max is `49` - `after`: The query cursor `String` for pagination +### getHighlightReels(params) + ```js + await client.getHighlightReels({ highlightReelIds: [highlightReelId] }) + ``` + > This will return the data of multiple highlights +- `params` + - `highlightReelIds`: An array of highlight reel id + +### getHighlightsByUsername(params) + ```js + await client.getHighlightsByUsername({ username }) + ``` + > This will return the highlights below a profile. +- `params` + - `username`: The username + +### getHighlightItemsByReel(params) + ```js + await client.getHighlightItemsByReel({ highlightReelId }) + ``` + > This will return the highlight items based on the id of the highlight +- `params` + - `highlightReelId`: The higlight reel id + + ## License MIT © [Jesús Lobos](https://jlobos.com/) diff --git a/helpers/index.js b/helpers/index.js index 4aa1a7b..9ecb6f4 100644 --- a/helpers/index.js +++ b/helpers/index.js @@ -24,7 +24,8 @@ module.exports = { full_name: 'XENIA', id: '184028108', pk: 184028108, - username: 'xenia' + username: 'xenia', + highlightReelId: 17890694692269640 } }, diff --git a/test/index.js b/test/index.js index ce6c7bb..e45bdde 100644 --- a/test/index.js +++ b/test/index.js @@ -139,6 +139,25 @@ test('getStoryItemsByReel', async t => { t.true(Array.isArray(storyItems)) }) +test('getHighlightReels', async t => { + const response = await client.getHighlightReels({ highlightReelIds: [users.Xenia.highlightReelId] }) + t.true(Array.isArray(response)) +}) + +test('getHighlightsByUsername', async t => { + const highlightItems = await client.getHighlightsByUsername({ + username: users.Xenia.username + }) + + t.true(Array.isArray(highlightItems)) +}) + +test('getHighlightItemsByReel', async t => { + const highlightItems = await client.getHighlightItemsByReel({ highlightReelId: users.Xenia.highlightReelId }) + + t.true(Array.isArray(highlightItems)) +}) + test('markStoryItemAsSeen', async t => { const storyItem = ( await client.getStoryItemsByHashtag({ From a8644c951edd17f699174ea524de5b81b6e8a155 Mon Sep 17 00:00:00 2001 From: "Zane J. Chua" Date: Thu, 22 Apr 2021 11:08:44 +0000 Subject: [PATCH 3/3] Add retrieving of IGTV and Tagged Photos --- lib/index.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0f19c99..cc99d7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -276,13 +276,12 @@ class Instagram { }).then(data => data.data.reels_media) } - async getHighlightsByUsername({ username }) { - const user = await this.getUserByUsername({ username }) + async getUserIdHighlights({ id }) { return this.request('/graphql/query/', { qs: { query_hash: '7c16654f22c819fb63d1183034a5162f', variables: JSON.stringify({ - user_id: user.id, + user_id: id, include_chaining: false, include_reel: false, include_suggested_users: false, @@ -295,12 +294,76 @@ class Instagram { .then(({ edges }) => edges.map(edge => edge.node)) } + async getHighlightsByUsername({ username }) { + const user = await this.getUserByUsername({ username }) + return this.getUserIdHighlights({ id: user.id }); + } + async getHighlightItemsByReel({ highlightReelId }) { const reels = await this.getHighlightReels({ highlightReelIds: [highlightReelId] }) if (reels.length === 0) return [] return reels[0].items } + async getUserIdTaggedPhotos({ id, first = 12, after = '' } = {}){ + return this.request.get('/graphql/query/', { + qs: { + query_hash: 'ff260833edf142911047af6024eb634a', + variables: JSON.stringify({ + id, + first, + after + }) + } + }) + .then(data => data.data.user.edge_user_to_photos_of_you) + .then(({count, page_info, edges}) => ({ + count, + page_info, + data: edges.map(edge => edge.node) + })) + } + + async getTaggedPhotosByUsername({ username, first, after }) { + const user = await this.getUserByUsername({ username }) + return this.getUserIdTaggedPhotos({ id: user.id, first, after }) + } + + async getMediaWithShortcode({ shortcode }) { + return this.request('/graphql/query/', { + qs: { + query_hash: '03f541f086ce0a9b31f67688ff9c1e09', + variables: JSON.stringify({ + shortcode + }) + } + }).then(data => data.data.shortcode_media) + } + + async getUserIdIGTV({ id, first = 12, after = '' } = {}) { + return this.request('/graphql/query/', { + qs: { + query_hash: 'bc78b344a68ed16dd5d7f264681c4c76', + variables: JSON.stringify({ + id, + first, + after + }) + } + }) + .then(data => data.data.user.edge_felix_video_timeline) + .then(({count, page_info, edges}) => ({ + count, + page_info, + data: edges.map(edge => edge.node) + })) + } + + async getIGTVByUsername({ username, first, after }) { + const user = await this.getUserByUsername({ username }) + return this.getUserIdIGTV({ id: user.id, first, after }) + } + async _getFollowData({ fieldName, queryHash, variables }) { return this.request('/graphql/query/', { qs: {