Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Highlights Support #170

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
3 changes: 2 additions & 1 deletion helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = {
full_name: 'XENIA',
id: '184028108',
pk: 184028108,
username: 'xenia'
username: 'xenia',
highlightReelId: 17890694692269640
}
},

Expand Down
107 changes: 107 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,113 @@ 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 getUserIdHighlights({ id }) {
return this.request('/graphql/query/', {
qs: {
query_hash: '7c16654f22c819fb63d1183034a5162f',
variables: JSON.stringify({
user_id: 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 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: {
Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down