jlobos / instagram-web-api

🤳 Instagram Private Web API client for Node
https://npmjs.com/instagram-web-api
MIT License
1.12k stars 185 forks source link

TypeError: Cannot read property 'user' of undefined #198

Closed austinkimchi closed 2 years ago

austinkimchi commented 3 years ago

The code I have been using has been working in the morning but after 2 hours of coding it seemed to stop after I tested it.

I tested with this code: `const Instagram = require('instagram-web-api') const { username, password } = process.env

const client = new Instagram({ username, password }); const instagram = await client.getUserByUsername({ username: 'instagram' }) ` Then I get the error: image

I used runkit to test this out to make sure my code wasn't wrong or anything....

image

Please help. I don't know if this is because of Instagram API down or anything but my earlier it was working. I tried changing IP address aswell and still errored out.

KevinYap commented 3 years ago

i also having this issue, anyone can help on this?

austinkimchi commented 3 years ago

I have spent multiple hours trying to find the issue but can't. I'm not sure what exactly is the problem but please help.

KevinYap commented 3 years ago

I get this error in my terminal: error - ./node_modules/instagram-web-api/lib/index.js:2:0 Module not found: Can't resolve 'fs'

JCGithu commented 3 years ago

Getting the same error

..\node_modules\instagram-web-api\lib\index.js:152 }).then(data => data.graphql.user) TypeError: Cannot read property 'user' of undefined

EDIT: So my solution was a stupid one. I forgot password was case-senstive so was inputting that wrong. I would recommend double-checking your log-in info and cookies.

3yezz commented 3 years ago

Hello No solution for the moment? image

OlivierDijkstra commented 3 years ago

Got the same error, login credentials are working fine. ` console.log('Credentials', process.env.INSTA_USER, process.env.INSTA_PASS);

const client = new Instagram({
  username: process.env.INSTA_USER,
  password: process.env.INSTA_PASS
});

let performImageFetch = true;

try {
  console.log('logging in 🔒...');

  await client.login();

  console.log('Login successfull ✅');
} catch (err) {
  performImageFetch = false;

  console.log('Login failed 🚫');

  if (err.status === 403) {
    console.log('Throttled 🚫');

    return;
  }

  if (err.error && err.error.message === 'checkpoint_required') {
    console.log('Challenge failed!', 'Performing new challenge...');

    const challengeUrl = err.error.checkpoint_url;
    await client.updateChallenge({ challengeUrl, choice: 1 });

    performImageFetch = true;
  }
}

if (performImageFetch) {
  console.log('Getting photos 📸... ');

  client
    .getPhotosByUsername({
      username: 'scorpiomodelmanagement'
    })
    .then((response) => {
      // console.log(response);
      console.log('Images received ✅');
      posts = response.user.edge_owner_to_timeline_media.edges;
    })
    .catch((error) => {
      console.log('Failed getting images 🚫');

      console.log(error);
    });

} `

Fails when I try to get the images using getPhotosByUsername. Fails on this.getUserByUsername because user is undefined.

Zegoverno commented 3 years ago

Same error here when using getFollowings and getUserByUsername... everything was working before a block from instagram, using the account is working fine, but with the library functions not

Zegoverno commented 3 years ago

I could fix that by removing the cookie from auth, working fine now

KevinYap commented 3 years ago

I could fix that by removing the cookie from auth, working fine now

do you mind share your code here? regarding on how to remove the cookie from auth, thanks!

bvrls commented 3 years ago

still no update?

banguncode commented 2 years ago

The code I have been using has been working in the morning but after 2 hours of coding it seemed to stop after I tested it.

I tested with this code: `const Instagram = require('instagram-web-api') const { username, password } = process.env

const client = new Instagram({ username, password }); const instagram = await client.getUserByUsername({ username: 'instagram' }) ` Then I get the error: image

I used runkit to test this out to make sure my code wasn't wrong or anything....

image

Please help. I don't know if this is because of Instagram API down or anything but my earlier it was working. I tried changing IP address aswell and still errored out.

  1. Create environment file .env
  2. Fill username=? and password=?
  3. Install npm i dotenv
  4. Import const dotenv = require("dotenv"); dotenv.config();
  5. Try again
austinkimchi commented 2 years ago

Never figured out and tried everything but I'm using another module to power this.

joris-delorme commented 2 years ago

@PrincessKimchi what is the module you use ?