During login: Uncaught (in promise) TypeError: Cannot read property 'map' of undefined
I need to pull links to IG content while the browser is minimized. If I minimize the window and reload the page, it won't load image URL's into the srcset of each div container UNTIL I bring the instagram tab back to front. This is why I want to try this library.
I used browserify to solve imports and added the following:
(function (process){
const Instagram = require('..')
const { username, password } = process.env
const client = new Instagram({ username:'username123', password: 'password123' })
console.log(client)
client
.login()
.then(() => {
client
.getProfile()
.then(console.log)
})
}).call(this,require('_process'))
I've added prints and it seems to get called properly as, after browserifying, adding the resulting 2.3mb file as a Chrome Snippet and running it prints:
credentials
. . .
password
:
"password123"
username
:
"username123"
However, just after that, I get an exception:
index4:56 Uncaught (in promise) TypeError: Cannot read property 'map' of undefined
at request.then.res (<anonymous>:56:46)
async login({ username, password } = {}) {
username = username || this.credentials.username
password = password || this.credentials.password
// Get CSRFToken from cookie before login
const { value } = await this.request('/', { resolveWithFullResponse: true })
.then(res => res.headers['set-cookie'].map(Cookie.parse)) //THIS IS WHERE THE ERROR POINTS AT
.then(res => res.find(cookie => cookie.key === 'csrftoken'))
.then(res => res.toJSON())
Am I doing something wrong? Also, if you happen to know about any JavaScript object or something similar where all the image URL's get saved to, that would already solve the case for me personally. Having a browser session running isn't an issue for my project but I need to be able to pull the links to the media when the browser window is minimized.
Thanks
I'm having the exact same issue. It looks like Instagram doesn't send the CSRF header anymore. When I look into the response, I can see CSRF token is being set into an object called _sharedData, like this:
<script type="text/javascript">
window._sharedData = {"activity_counts":null,"config":{"csrf_token":"OE3Ojuq1nRZ2sMtB2zVpFXQDEepH7ZfZ","viewer":null}, ...}
...
</script>
I'm having the same issue. Have you solved it?
Same here. Any fix?