user-instagram
Advanced tools
Comparing version 2.1.8 to 2.1.9
{ | ||
"name": "user-instagram", | ||
"version": "2.1.8", | ||
"version": "2.1.9", | ||
"description": "Get user data and feed content by scraping Instagram's user page. No OAuth needed.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const axios = require('axios'); | ||
const {normalizeUrl, normalizePostUrl} = require('../src/util'); | ||
const UnableToFetchUserDataError = require('./Exceptions/UnableToFetchUserDataError'); | ||
const UnableToFetchPostDataError = require('./Exceptions/UnableToFetchPostDataError'); | ||
@@ -7,2 +9,3 @@ /** | ||
* @param {string} username | ||
* @throws UnableToFetchUserDataError | ||
* @return {Promise<Object>} | ||
@@ -17,6 +20,5 @@ */ | ||
}; | ||
const GQL = await axios(REQUEST_PARAMETERS) | ||
.catch(reject); | ||
const user = GQL.data.graphql.user; | ||
resolve({ | ||
axios(REQUEST_PARAMETERS).then(GQL => { | ||
const user = GQL.data.graphql.user; | ||
resolve({ | ||
link: URL.replace('/?__a=1', ''), | ||
@@ -66,2 +68,5 @@ id: user.id, | ||
}); | ||
}).catch(() => { | ||
reject(UnableToFetchUserDataError.fromUsername(username)); | ||
}); | ||
}); | ||
@@ -82,73 +87,77 @@ }; | ||
}; | ||
const GQL = await axios(REQUEST_PARAMETERS) | ||
.catch(reject); | ||
const media_data = GQL.data.graphql.shortcode_media; | ||
const has_caption = media_data.edge_media_to_caption.edges.length > 0; | ||
resolve({ | ||
link: URL.replace('/?__a=1', ''), | ||
shortcode: media_data.shortcode, | ||
dimensions: media_data.dimensions, | ||
displayUrl: media_data.display_url, | ||
isVideo: media_data.is_video, | ||
wasCaptionEdited: media_data.caption_is_edited, | ||
caption: has_caption? media_data.edge_media_to_caption.edges[0].node.text : null, | ||
commentsCount: media_data.edge_media_to_parent_comment.count, | ||
areCommentsDisabled: media_data.comments_disabled, | ||
takenAt: media_data.taken_at_timestamp, | ||
likesCount: media_data.edge_media_preview_like.count, | ||
location: media_data.location ? { | ||
id: media_data.location.id, | ||
hasPublicPage: media_data.location.has_public_page, | ||
name: media_data.location.name, | ||
slug: media_data.location.slug, | ||
jsonName: media_data.location.address_json, | ||
} : null, | ||
owner: { | ||
id: media_data.owner.id, | ||
username: media_data.owner.username, | ||
profilePicture: media_data.owner.profile_pic_url, | ||
full_name: media_data.owner.full_name, | ||
postsCount: media_data.owner.edge_owner_to_timeline_media, | ||
followersCount: media_data.owner.edge_followed_by, | ||
isPrivate: media_data.owner.is_private, | ||
isVerified: media_data.owner.is_verified, | ||
}, | ||
isAnAd: media_data.is_ad, | ||
childrenPictures: media_data.edge_sidecar_to_children && media_data.edge_sidecar_to_children.edges ? media_data.edge_sidecar_to_children.edges.map(edge => { | ||
return { | ||
id: edge.node.id, | ||
shortcode: edge.node.shortcode, | ||
dimensions: edge.node.dimensions, | ||
displayUrl: edge.node.display_url, | ||
isVideo: edge.node.is_video | ||
} | ||
}) : [], | ||
comments: media_data.edge_media_to_parent_comment.edges.map(edge => { | ||
return { | ||
id: edge.node.id, | ||
text: edge.node.text, | ||
createdAt: edge.node.created_at, | ||
author: { | ||
id: edge.node.owner.id, | ||
isVerified: edge.node.owner.is_verified, | ||
username: edge.node.owner.username, | ||
profilePicture: edge.node.owner.profile_pic_url | ||
}, | ||
likesCount: edge.node.edge_liked_by.count | ||
} | ||
}), | ||
taggedUsers: (media_data.edge_media_to_tagged_user.edges) ? media_data.edge_media_to_tagged_user.edges.map(tag => { | ||
return { | ||
fullName: tag.node.user.full_name, | ||
id: tag.node.user.id, | ||
isVerified: tag.node.user.is_verified, | ||
username: tag.node.user.username, | ||
tagLocation: { | ||
x: tag.node.x, | ||
y: tag.node.y | ||
axios(REQUEST_PARAMETERS) | ||
.then(GQL => { | ||
const media_data = GQL.data.graphql.shortcode_media; | ||
const has_caption = media_data.edge_media_to_caption.edges.length > 0; | ||
resolve({ | ||
link: URL.replace('/?__a=1', ''), | ||
shortcode: media_data.shortcode, | ||
dimensions: media_data.dimensions, | ||
displayUrl: media_data.display_url, | ||
isVideo: media_data.is_video, | ||
wasCaptionEdited: media_data.caption_is_edited, | ||
caption: has_caption? media_data.edge_media_to_caption.edges[0].node.text : null, | ||
commentsCount: media_data.edge_media_to_parent_comment.count, | ||
areCommentsDisabled: media_data.comments_disabled, | ||
takenAt: media_data.taken_at_timestamp, | ||
likesCount: media_data.edge_media_preview_like.count, | ||
location: media_data.location ? { | ||
id: media_data.location.id, | ||
hasPublicPage: media_data.location.has_public_page, | ||
name: media_data.location.name, | ||
slug: media_data.location.slug, | ||
jsonName: media_data.location.address_json, | ||
} : null, | ||
owner: { | ||
id: media_data.owner.id, | ||
username: media_data.owner.username, | ||
profilePicture: media_data.owner.profile_pic_url, | ||
full_name: media_data.owner.full_name, | ||
postsCount: media_data.owner.edge_owner_to_timeline_media, | ||
followersCount: media_data.owner.edge_followed_by, | ||
isPrivate: media_data.owner.is_private, | ||
isVerified: media_data.owner.is_verified, | ||
}, | ||
isAnAd: media_data.is_ad, | ||
childrenPictures: media_data.edge_sidecar_to_children && media_data.edge_sidecar_to_children.edges ? media_data.edge_sidecar_to_children.edges.map(edge => { | ||
return { | ||
id: edge.node.id, | ||
shortcode: edge.node.shortcode, | ||
dimensions: edge.node.dimensions, | ||
displayUrl: edge.node.display_url, | ||
isVideo: edge.node.is_video | ||
} | ||
} | ||
}) : null | ||
}) : [], | ||
comments: media_data.edge_media_to_parent_comment.edges.map(edge => { | ||
return { | ||
id: edge.node.id, | ||
text: edge.node.text, | ||
createdAt: edge.node.created_at, | ||
author: { | ||
id: edge.node.owner.id, | ||
isVerified: edge.node.owner.is_verified, | ||
username: edge.node.owner.username, | ||
profilePicture: edge.node.owner.profile_pic_url | ||
}, | ||
likesCount: edge.node.edge_liked_by.count | ||
} | ||
}), | ||
taggedUsers: (media_data.edge_media_to_tagged_user.edges) ? media_data.edge_media_to_tagged_user.edges.map(tag => { | ||
return { | ||
fullName: tag.node.user.full_name, | ||
id: tag.node.user.id, | ||
isVerified: tag.node.user.is_verified, | ||
username: tag.node.user.username, | ||
tagLocation: { | ||
x: tag.node.x, | ||
y: tag.node.y | ||
} | ||
} | ||
}) : null | ||
}); | ||
}) | ||
.catch(() => { | ||
reject(UnableToFetchPostDataError.fromShortcode(shortcode)); | ||
}); | ||
}); | ||
}; |
@@ -7,2 +7,2 @@ require("../index").getUserData("edouard_courty") | ||
.then(console.log) | ||
.catch(console.error); | ||
.catch(console.error); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10415
8
207