Skip to content

Commit

Permalink
Switch getHome('end_cursor') endpoint to graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
revall authored May 20, 2020
2 parents 6bb9d9c + 5ce2bc1 commit be2757e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ await client.logout()
### getHome()
```js
const feed = await client.getHome()
const feed = await client.getHome('KGEAxpEdUwUrxxoJvxRoQeXFGooSlADHZ8UaDdSWbnOIxxoUUhyciJ7EGlxNlZjaYcUaXTgUM00qyBrgBhUsLezIGqVTlxqausga5W-fVax9xRryaBdN1EnIGvdQFgzxoMgaFoLO7v7xWQA=')
```
> Get home feed timeline, media shared by the people you follow.
- `params`
- `end_cursor` (`String`) for pagination

### getUserByUsername(params)
```js
Expand Down
19 changes: 16 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,22 @@ class Instagram {
return this.request('/accounts/logout/ajax/')
}

// https://github.com/jlobos/instagram-web-api/issues/23
async getHome() {
return this.request('/?__a=1').then(data => data.graphql.user)
async _getHomeData({ queryHash, variables }) {
return this.request('/graphql/query/', {
qs: {
query_hash: queryHash,
variables: JSON.stringify(variables)
}
}).then(data => data)
}

async getHome(mediaItemCursor) {
return this._getHomeData({
queryHash: '01b3ccff4136c4adf5e67e1dd7eab68d',
variables: {
fetch_media_item_cursor: mediaItemCursor
}
})
}

async getUserByUsername({ username }) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,10 @@ test('getMediaLikes', async t => {
t.true(Array.isArray(response.edges))
t.true(typeof response.page_info === 'object')
})

test('getHome', async t => {
const { status } = await client.getHome(
'KGEAxpEdUwUrxxoJvxRoQeXFGooSlADHZ8UaDdSWbnOIxxoUUhyciJ7EGlxNlZjaYcUaXTgUM00qyBrgBhUsLezIGqVTlxqausga5W-fVax9xRryaBdN1EnIGvdQFgzxoMgaFoLO7v7xWQA='
)
t.is(status, 'ok')
})

0 comments on commit be2757e

Please sign in to comment.