Giter Site home page Giter Site logo

edouardcourty / user-instagram Goto Github PK

View Code? Open in Web Editor NEW
84.0 1.0 19.0 696 KB

This module allows you to get the data of any user or post on Instagram.

JavaScript 100.00%
instagram instagram-scraper instagram-feed node-instagram user-instagram

user-instagram's Introduction

User Instagram - DEPRECATED

Downloads Node.js CI

The end

Thursday 07 2022.
Instagram's API & Authentication changed a lot and I don't have the time to update and reverse-engineer everything again.
I have no choice but to deprecate this module.
If you want to become the official maintainer, feel free to open an issue and we'll get in touch!

Thanks to the thousands of people that used this module through the years!
Big love from Paris!

Usage

Use this module in your projet by installing it with npm install user-instagram.

Here is a quick example or usage:

const instagram = require('user-instagram');

await instagram.authenticate('my_instagram_username', 'my_instagram_password');

// Fetching a user
instagram.getUserData('edouard_courty').then(userData => {
  // Do whatever you need to to with this data
  console.log(`My username is ${userData.getUsername()}.`);
})

// Fetching a post
instagram.getPostData('CUc7tBPFXvP').then(postData => {
  // Do whatever you need to to with this data
  console.log(`The caption of this post is ${postData.getCaption()}.`);
})

Documentation

In the previous versions of user-instagram, only a small amount of requests could be sent every day without getting rate-mimited.
Couple of issues were submitted about this problem and it's the main reason why I decided to refactor this module, and add an authentication method to it.

Authentication

The authenticate method takes two mandatory parameters: username and password.
A good way to keep these strings safe is storing them in an uncommited file in your repo like some instagram_config.json file structured like the following:

{
  "username": "your username here",
  "password": "your password here"
}

Then use it like this:

const instagram = require('user-instagram');
const {username, password} = require('instagram_config.json')

await instagram.authenticate(username, password);

Getting a user's data

When logged in, you can request the data of any public user you want, plus the private users that your account follows.
The getUserData method takes only one parameter: the username of the user to be fetched.

This method will return a promise holding a User class, containing getters for all the interesting properties of this class.

Available user properties

All the boolean values are accessed with the following methods: (the function names should be self explanatory of their return value)

  • isVerified()
  • isPrivate()
  • isBusinessAccount()
  • isProfessionalAccount()
  • hasClips()
  • hasArEffect()
  • hasChannel()
  • hasGuides()
  • isHidingLikesAndViewsCount()
  • hasJoinedRecently()

All the non-boolean values are accessed with the following methods:

  • getUsername()
  • getBiography()
  • getPublicationsCount()
  • getFollowersCount()
  • getExternalUrl()
  • getFollowingCount()
  • getFullName()
  • getHighlightsReelsCount()
  • getId()
  • getBusinessAddressJson()
  • getBusinessContactMethod()
  • getBusinessEmail()
  • getBusinessPhoneNumber()
  • getBusinessCategoryName()
  • getOverallCategoryName()
  • getCategoryEnum()
  • getProfilePicture()
  • getHdProfilePicture()
  • getPronouns()
  • getMedias()

Getting a post's data

When logged in, you can request the data of any public post you want, plus the posts of the private accounts that your account follows.
The getPostData method takes only one parameter: the shortcode of the post to be fetched.

This method will return a promise holding a Post class, containing getters for all the interesting properties of this class.

Available post properties

All the boolean values are accessed with the following methods: (the function names should be self explanatory of their return value)

  • isVideo()
  • areCommentsDisabled()
  • areLikesAndViewsCountDisabled()
  • isPaidPartnership()
  • isAd()
  • hasAudio()

All the non-boolean values are accessed with the following methods:

  • getId()
  • getType()
  • getShortcode()
  • getDimensions()
  • getDisplayUrl()
  • getVariants()
  • getAccessibilityCaption()
  • getTaggedUsers()
  • getCaption()
  • getCommentsCount()
  • getComments()
  • getDate()
  • getLikesCount()
  • getLocation()
  • getOwner()
  • getChildren()
  • getVideoViewsCount()
  • getVideoPlaysCount()

Generic properties shared across the module

Each Media from the getMedias() in the User class method is a Media class that has these getters:

  • getType()
  • getId()
  • getShortcode()
  • getCaption()
  • getDimensions()
  • getDisplayUrl()
  • getTaggedUsers()
  • isVideo()
  • getAccessibilityCaption()
  • areCommentsDisabled()
  • getCommentsCount()
  • getLikesCount()
  • getTimestamp()
  • getLocation()
  • getChildren()
  • hasAudio()
  • getViewsCount()
  • getVideoUrl()

Every TaggerUser from getTaggedUsers() in a Post or a User.getMedias() hold the following getters:

  • getTagXPosition()
  • getTagYPosition()
  • getFullName()
  • getId()
  • isVerified()
  • getProfilePictureUrl()
  • getUsername()

Every dimension value from getDimensions() from a Media or a Post is a Dimension class with a bult-in aspect-ratio calculator:

  • getHeight()
  • getWidth()
  • getAspectRatio()

ยฉ Edouard Courty - 2021

user-instagram's People

Contributors

abhint avatar aman-14 avatar edouardcourty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

user-instagram's Issues

Unkown error

InstagramGenericError: Unkown error, please submit an issue on GitHub with the following error message: Request failed with status code 400
17:30:45 1|stars | at /var/www/node_modules/user-instagram/src/Instagram/Infrastructure/InstagramRepository.js:382:23
17:30:45 1|stars | at processTicksAndRejections (internal/process/task_queues.js:97:5)

i do get this on auth

Safe to use??

Is this kind of api hitting safe to use. I mean, these apis are not mentioned anywhere officially by facebook/instagram.
What if tomorrow they change these apis, the entire project is dependent on it.

Comments?

Is it possible to scrape the comments for a user's media post too?

UnableToFetchPostDataError when using AWS

Hi, first of all thanks for all you've done on this it's really been a big help.

I'm running into a problem where when I try to use this package in my app locally, theres no problem but when I deploy my app to AWS I keep running into this issue where the scrapper is unable to find the post and I'm getting:

UnableToFetchPostDataError: An error occured while fetching post data for shortcode CIyq3yGD5Pd. Maybe this post does not exist ?

Any ideas why?

Unable to get user data

When plugin does it's request to instagram, instagram graph api is returning 302 with no data. This is causing:

scrape.js:18 Uncaught (in promise) TypeError: Cannot read property 'user' of undefined

does not find users

UnableToFetchUserDataError: An error occured while fetching data for user instasamka. Maybe this user does not exist ?
IMG_20210716_001107

UnableToFetchUserDataError

I tried to get data of user 'tassakpro'. And i get this error.

UnableToFetchUserDataError: An error occured while fetching data for user tassakpro. Maybe this user does not exist ?
at Function.fromUsername (/app/node_modules/user-instagram/src/Exceptions/UnableToFetchUserDataError.js:7:12)
at /app/node_modules/user-instagram/src/scrape.js:67:43
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:97:5)

User exists. https://www.instagram.com/tassakpro/
It's giving error on github. on my pc, it's working. How can i fix that?

TypeError: Cannot read property 'user' of undefined

I know it may be the duplicate of another problem, but for me, I changed everything, tried to run it on different computers, different VPS and stuff and still the same error

The Compelete Error:

(node:3638) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined

    at /rbd/pnpm-volume/25d72025-e3a1-4ce5-8141-f18084a1e354/node_modules/.registry.npmjs.org/user-instagram/2.1.3/node_modules/user-instagram/src/scrape.js:23:37

    at processTicksAndRejections (internal/process/task_queues.js:88:5)

(node:3638) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:3638) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

i also tried using vpn on everything and still the same.....

Crash when user not found.

When I try a search user without an account my app crash with this error:

var error = new Error(message);
              ^

Error: Request failed with status code 404
    at createError (C:\Users\Andrey\Desktop\jobs\testdiscord\node_modules\user-instagram\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\Andrey\Desktop\jobs\testdiscord\node_modules\user-instagram\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\Andrey\Desktop\jobs\testdiscord\node_modules\user-instagram\node_modules\axios\lib\adapters\http.js:244:11)
    at IncomingMessage.emit (node:events:341:22)
    at endReadableNT (node:internal/streams/readable:1294:12)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {..SOME ERROR..}```

429 response code

This Package working smoothly until last week. but right now I'm getting 429 error code. does Instagram change anything?

Error when deploying severless function

Hi!

First of all, thank you for creating this library!
Unfortunately, I cannot get it to work in production.

I'm working on a Next.JS application and use this library inside of a serverless function.
When I'm testing it locally, everything seems to work fine.

However, when I deploy the application using Vercel, I get the following error:
An error occured while fetching data for user boexclusives. Maybe this user does not exist ?

Do you have any idea why this is happening?

Thanks in advance!

Show only a few Posts

The module only shows a few posts, not all
I have 74 and the module only gives me 10

Error should be rejected

InstagramGenericError should be sent to reject function here.

As currently it is only returned, the promise keeps waiting and never fulfill. This is a major bug and should be fixed.

Only works on local host

I'm using the library to create an iscord bot, however I can't find a host that this library works with.

Fix description of project

Hi, thanks for package, your can update description in JSON exist one error:

"subscriberCount": 444,
is
"subscribersCount": 444,

The key on json have one error.

Basic use of the package

I literally have this on my code below:

const IG = require("user-instagram");

IG("sadi.boii")
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  });

But I still get the following error message

UnableToFetchUserDataError: An error occured while fetching data for user sadi.boii. Maybe this user does not exist ?
    at Function.fromUsername (/home/junior/Desktop/DJ-COACH-EWALLET/node_modules/user-instagram/src/Exceptions/UnableToFetchUserDataError.js:7:12)
    at /home/junior/Desktop/DJ-COACH-EWALLET/node_modules/user-instagram/src/scrape.js:67:43

Keep "The server has sent an unsuccessful response. The rate limit has been hit, retry later." Although I havent send any request

I tried uploading my backend on digital Ocean and authenticated my Instagram account at first everything was working great but then after leaving the backend for a day or two I couldn't send any request to Instagram my guess is that something is wrong with caching the credentials. I can see that you guys try to re-authenticate the user if the session expires. I am not sure if that's the issue or note but I am just trying to think of a solution

"Please submit an Issue on Github"

Hi, today i started using this NPM and got a weird error. Please help :(

Error: Unknown error, please submit an issue on GitHub.
at C:\Users---\OneDrive\Dokumente---\Discord\DC Bots\JoniBot v13\node_modules\user-instagram\src\Instagram\Infrastructure\InstagramRepository.js:374:23
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)

The Code:
const instagram = require('user-instagram');
let name = args[0];
if(!name) return message.channel.send('Enter an account to search for!');
await instagram.authenticate(process.env.username, process.env.passwort);
instagram.getUserData(name).then(userData => {
let embed = new MessageEmbed()
.setTitle(**Profile from: ${userData.getUsername()}**)
message.channel.send({embeds:[embed]});

    })

Can running getUserData too often lead to rate limiting the application?

Hi there!

I am using instagram.getUserData() function with a node-cron in 5 minutes interval to check for new photos being posted. I have noticed, that using instagram.authenticate() too often leads to the application getting rate limited very fast, so I tried bypassing it with only logging in once during app initialization. That little trick solved the problem, however I was wondering if my app could still gate rate limited for scraping user data too often. If so, what is the optimal interval to prevent rate limit?

Thanks in advance for all of your answers!

Issue fetching the username

It was working fine previously, and I didn't change any code.
It could be an issue of IG updating their GQL?
I'm pretty sure the user exists, I also tested with other users.

/home/pi/apps/roby/node_modules/user-instagram/src/scrape.js:18
    const user = GQL.data.graphql.user;
                                  ^

TypeError: Cannot read property 'user' of undefined

and

UnableToFetchUserDataError: An error occured while fetching data for user oio.studio. Maybe this user does not exist ?
    at Function.fromUsername (/Users/ml/www/oio/apps/roby/node_modules/user-instagram/src/Exceptions/UnableToFetchUserDataError.js:7:12)
    at /Users/ml/www/oio/apps/roby/node_modules/user-instagram/src/scrape.js:67:43

Could this be shut down by Instagram?

Hi, thanks for developing this, it is extremely handy. I just wanted to see if you had any idea about what Instagram's attitudes towards these scrapers. I'm creating an app which needs Instagram info and the Basic API is a pain. Do you think there is a relatively high probability that Instagram will be able to shut off access to APIs such as these or do you think it's secure?

This may be a stupid question but would love to get your opinion on it as the developer.

UnableToFetchUserDataError

Hello! When I try to get information about the user, I'm getting the error.

UnableToFetchUserDataError: An error occured while fetching data for user lwjerri. Maybe this user does not exist ?
    at Function.fromUsername (C:\Users\Andrey\Desktop\jobs\japi\node_modules\user-instagram\src\Exceptions\UnableToFetchUserDataError.js:7:12)
    at C:\Users\Andrey\Desktop\jobs\japi\node_modules\user-instagram\src\scrape.js:67:43
    at processTicksAndRejections (node:internal/process/task_queues:93:5)

Issues using package

I was trying to use this package for my bot and whenever I run the command, in my console it says:

(node:979) UnhandeledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined
     at /home/runner/MLlama-Bot/node_modules/user-instagram/src/scrape.js:23:37
     at runMicrotasks (<anonymous>)
     at processTicksAndRejections (internal/process/task_queues.js:97:5)
...

Refused to set unsafe header 'user-agent' & CORS cache-control rejection

As of version 2.1.3 this package is broken and unusable. It works as intended on version 2.0.8 but you changed the request headers after that version which is causing the breaking bug.

You are setting an unsafe header 'user-agent' causing this error : Refused to set unsafe header "user-agent"

And there's also an invalid field cache control that returns the following error.

Access to XMLHttpRequest at 'https://www.instagram.com/xyz/?__a=1' from origin 'https://www.mysite.com' has been blocked by CORS policy: Request header field cache-control is not allowed by Access-Control-Allow-Headers in preflight response.

Can you please revert things to how they were or remove the new request parameters?

No session found when running on google cloud platform

Hey, I have an issue with login process. Whenever I try to authenticate it works perfectly if I run the app on my PC, but I have hosted it on GCP, It says that "No session found, Did you authenticate?". This happens only on GCP and not on local system. I have a windows 10 machine and debian 10 on gcp.
Screenshot 2022-03-27 163829

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.