diff --git a/README.md b/README.md index 67d4bd3..e2cb466 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,8 @@ const client = new Instagram({ username, password, cookieStore }) * [.getPhotosByUsername({username, first, after})](#getphotosbyusernameparams) * [.getPrivateProfilesFollowRequests(cursor)](#getPrivateProfilesFollowRequests) * [.getChainsData({ userId })](#getChainsData) + * [.getMediaLikes({ shortcode, first, after })](#getMediaLikesParams) + * [.getMediaComments({ shortcode, first, after })](#getMediaCommentsParams) ### Instagram(credentials, opts) ```js @@ -470,6 +472,42 @@ await client.getPhotosByHashtag({ hashtag: 'unicorn' }) > This will return the similar accounts, that you see, when you click on the ARROW in a profile. - `params` - `userId`: The user id + +### getMediaLikes(params) + ```js + await client.getMediaLikes({ shortcode: 'B-0000000', first: '49', after: '' }) + ``` + > This will return the media likes. + - `params` + - `shortcode`: The shortcode media like this: https://www.instagram.com/p/B-00000000/, only put shortcode like this : B-000000000 + - `first`: A `number` of records to return max is `49` + - `after`: The query cursor `String` for pagination + +### getMediaComments(params) + ```js + await client.getMediaComments({ shortcode: 'B-0000000', first: '12', after: '' }).catch((error) => { + console.log(error); + }) + .then((response) => { + console.log(response); + }); + + //The query cursor 'after' maybe return an array, if array you need to convert like this: + let pointer = response.page_info.end_cursor; + // this will try to convert array to json stringify + try{ + pointer = JSON.parse(pointer); + pointer = JSON.stringify(pointer); + }catch(e){ + console.log('Pointer is not array!, don't need to be converted!'); + } + + ``` + > This will return the media comments. + - `params` + - `shortcode`: The shortcode media like this: https://www.instagram.com/p/B-00000000/, only put shortcode like this : B-000000000 + - `first`: A `number` of records to return max is `49` + - `after`: The query cursor `String` for pagination ## License diff --git a/lib/index.js b/lib/index.js index 2841290..ec02709 100644 --- a/lib/index.js +++ b/lib/index.js @@ -292,14 +292,14 @@ class Instagram { include_reel: false, include_suggested_users: false, include_logged_out_extras: false, - include_highlight_reels:false + include_highlight_reels: false }) } }) .then(data => data.data.user.edge_chaining) - .then(({ edges }) => edges.map(edge => edge.node)); + .then(({ edges }) => edges.map(edge => edge.node)) } - + async getActivity() { return this.request('/accounts/activity/?__a=1').then( data => data.graphql.user @@ -396,6 +396,42 @@ class Instagram { ) } + async getMediaComments({ shortcode, first = 12, after = '' }) { + return this.request('/graphql/query/', { + qs: { + query_hash: 'bc3296d1ce80a24b1b6e40b1e72903f5', + variables: JSON.stringify({ shortcode, first, after }) + } + }) + .then(response => response.data.shortcode_media || {}) + .then(media => media.edge_media_to_parent_comment || {}) + .then(({ count = 0, page_info = {}, edges = [] }) => ({ + count, + page_info, + edges + })) + } + + async getMediaLikes({ shortcode, first = 12, after = '' }) { + return this.request('/graphql/query/', { + qs: { + query_hash: 'd5d763b1e2acf209d62d22d184488e57', + variables: JSON.stringify({ + shortcode, + first, + after + }) + } + }) + .then(response => response.data.shortcode_media || {}) + .then(media => media.edge_liked_by || {}) + .then(({ count = 0, page_info = {}, edges = [] }) => ({ + count, + page_info, + edges + })) + } + async addComment({ mediaId, text, replyToCommentId }) { return this.request.post(`/web/comments/${mediaId}/add/`, { form: { comment_text: text, replied_to_comment_id: replyToCommentId } diff --git a/test/index.js b/test/index.js index 59c3664..0125fb4 100644 --- a/test/index.js +++ b/test/index.js @@ -256,3 +256,20 @@ test('getChainsData', async t => { const response = await client.getChainsData({ userId: users.Maluma.id }) t.true(Array.isArray(response)) }) + +test('getMediaComments', async t => { + const response = await client.getMediaComments({ + shortcode: 'BWl6P', + first: 12 + }) + t.true(Number.isInteger(response.count)) + t.true(Array.isArray(response.edges)) + t.true(typeof response.page_info === 'object') +}) + +test('getMediaLikes', async t => { + const response = await client.getMediaLikes({ shortcode: 'BWl6P', first: 12 }) + t.true(Number.isInteger(response.count)) + t.true(Array.isArray(response.edges)) + t.true(typeof response.page_info === 'object') +})