Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

user-instagram

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

user-instagram - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0

6

index.js

@@ -1,2 +0,2 @@

const handle = require("./src/scrape");
const {getUserData, getPostData} = require("./src/scrape");

@@ -7,2 +7,4 @@ /**

*/
module.exports = handle;
module.exports = getUserData;
module.exports.getUserData = getUserData;
module.exports.getPostData = getPostData;
{
"name": "user-instagram",
"version": "2.0.9",
"version": "2.1.0",
"description": "Get user data and feed content by scraping Instagram's user page. No OAuth needed.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ # User-Instagram

## Introduction
The aim of this module is to provide an easy way to retrieve a user's Instagram data.
The aim of this module is to provide an easy way to retrieve a user's or a post data on Instagram.
This module is available on NPM.

@@ -21,5 +21,11 @@ ```

userInstagram("edouard_courty")
// Gets informations about a user
userInstagram("edouard_courty") // Same as getUserData()
.then(console.log)
.catch(console.error);
// Gets information about a post
userInstagram.getPostData("CD9EMe5sHP5")
.then(console.log)
.catch(console.error)
```

@@ -29,3 +35,3 @@

The output will look like the following:
The getUserData's JSON output will look like this:
```json

@@ -48,4 +54,38 @@ {

```
The getPostData's JSON output will look like that:
```json
{
"id": "<postId>",
"shortcode": "<postShortCode>",
"dimensions": {
"height": 1080,
"width": 1920
},
"caption": "<thePicturesCaption>",
"likesCount": 125,
"commentsCount": 26,
"comments": [
{
"id": "<commentId>",
"text": "<commentText>",
"author": {}
}
],
"location": {
"id": "<locationId>",
"name": "<locationName>",
"slug": "<locationSlug>"
},
"childrenPictures": [],
"owner": {
"username": "<ownerUsername>",
"full_name": "<ownerFullName",
"isPrivate" : true,
"isVerified": false
}
}
```
This module uses ES6 Promises.
© 2020 - Edouard Courty
const axios = require("axios");
const {normalizeUrl} = require("../src/util");
const {normalizeUrl, normalizePostUrl} = require("../src/util");

@@ -9,3 +9,3 @@ /**

*/
module.exports = (username) => {
module.exports.getUserData = (username) => {
return new Promise(async (resolve,reject) => {

@@ -36,2 +36,3 @@ const REQUEST_PARAMETERS = {

accountCategory: user.business_category_name,
linkedFacebookPage: user.connected_fb_page,
isPrivate: user.is_private,

@@ -43,2 +44,15 @@ isVerified: user.is_verified,

postsCount: user.edge_owner_to_timeline_media.count,
// savedMedia: {
// count: user.edge_saved_media.count,
// savedMedias: user.edge_saved_media.edges.map(edge => {
// return {
// id: edge.node.id,
// shortcode: edge.node.shortcode,
// url: `https://www.instagram.com/p/${edge.node.shortcode}/`,
// owner: edge.node.owner,
// commentCount: edge.node.edge_media_to_comment.count,
// likesCount: edge.node.edge_liked_by.count
// }
// })
// },
posts: user.edge_owner_to_timeline_media.edges.map(edge => {

@@ -74,1 +88,74 @@ let hasCaption = edge.node.edge_media_to_caption.edges[0];

};
module.exports.getPostData = (shortcode) => {
return new Promise(async (resolve, reject) => {
const REQUEST_PARAMETERS = {
method: "GET",
url: normalizePostUrl(shortcode),
headers: {
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36",
"authority": "www.instagram.com",
"cache-control": "max-age=0"
}
};
const GQL = await axios(REQUEST_PARAMETERS)
.catch(reject);
if (GQL) {
let media_data = GQL.data.graphql.shortcode_media;
resolve({
link: REQUEST_PARAMETERS.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: media_data.edge_media_to_caption.edges[0].node.text,
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: {
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,
},
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.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
}
})
});
}
});
};
module.exports = {
/**
* Bitch give me Regex, in case stoopid people use this module
* @param string

@@ -12,3 +11,14 @@ * @return string

return string += "/?__a=1";
}
},
/**
* @param string
* @return string
*/
normalizePostUrl: (string) => {
if (!string.match(/instagram\.com\/p\/[^\/]*/)) {
string = `https://www.instagram.com/p/${string}`;
}
return string += "/?__a=1";
},
};

@@ -1,3 +0,7 @@

require("../index")("edouard_courty")
require("../index").getUserData("edouard_courty")
.then(console.log)
.catch(console.error);
require("../index").getPostData("CD9EMe5sHP5")
.then(console.log)
.catch(console.error);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc