I get these errors when i'm trying to subscribe with the function subscribeUserPosts().
When I start the program I get this error once:
```js
TypeError: Cannot read property 'findIndex' of null
at C:\Users\admin\Documents\GitHub\project\node_modules\scraper-instagram\index.js:437:46
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```
And then I get this when the account that i want to subscribe to has posted something:
```js
TypeError: Cannot read property 'edges' of undefined
at C:\Users\admin\Documents\GitHub\project\node_modules\scraper-instagram\index.js:290:46
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```
I don't really know what's happening
lastPostsarray of posts - last posts
This property is empty ([]) when the profile doesn't have any post but null if access is false (denied).
And :
accessboolean - access to the profile's feed
Conclusion : the subscribed profile is private and either you are not logged in to your Instagram account or you are not following the subscribed profile.
At [`index.js:437`](https://git.kaki87.net/KaKi87/ig-scraper/src/branch/master/index.js#L437) :
```js
const lastPostIndex = profile.lastPosts.findIndex(post => post.shortcode === lastPostShortcode);
```
The error :
> `Cannot read property 'findIndex' of null`
As the documentation stipulates :
> `lastPosts` *array of posts* - last posts
This property is empty (`[]`) when the profile doesn't have any post but `null` if `access` is `false` (denied).
And :
> `access` *boolean* - access to the profile's feed
Conclusion : the subscribed profile is private and either you are not logged in to your Instagram account or you are not following the subscribed profile.
But I checked before if I was logged in and if I followed the account I wanted to "subrscribe" to. In fact even logged in, I can't use subscribeUserPosts() for any private account. Even though I am logged in.
I can see my profile with the this: ...but the error is still the same
When I try to "subscribe" to a public account it seems to work at first, but then when a new post is detected, I just get undefined in the console instead of the post information.
The shortcodes for private accounts are not supported in the getPost() function. I i try, I one of the errors I got yesterday:
Yes, thank you for responding so quick.
But I checked before if I was logged in and if I followed the account I wanted to "subrscribe" to. In fact even logged in, I can't use `subscribeUserPosts()` for any private account. Even though I am logged in.
I can see my profile with the this: ...but the error is still the same
```js
InstaClient.authBySessionId(sessionid)
.then(account => console.log(account))
.catch(err => console.error(err));
```
I checked everything and the error didn't change.
I also discovered two other things:
* When I try to "subscribe" to a public account it seems to work at first, but then when a new post is detected, I just get `undefined` in the console instead of the post information.
* The shortcodes for private accounts are not supported in the `getPost()` function. I i try, I one of the errors I got yesterday:
```js
TypeError: Cannot read property 'edges' of undefined
at C:\Users\admin\Documents\GitHub\project\node_modules\scraper-instagram\index.js:290:46
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```
Thanks for the time and help!
Regarding subscribing public profiles though, I have a Discord bot running 24/7 which is simultaneously subscribed to 3 profiles and reposting their posts on a public community server, and it's been working fine for months now.
Alright, investigating now.
Regarding subscribing public profiles though, I have a Discord bot running 24/7 which is simultaneously subscribed to 3 profiles and reposting their posts on a public community server, and it's been working fine for months now.
but ther is no shortcode in post, so post.shortcode === undefined is always true
but there is post.link
Ok I just found out why I couldn't get the posts. It was dumb from me: In the documentation and in my code, for `subscribeUserPosts()`, there was:
```js
InstaClient.subscribeUserPosts(username, (post, err) => {
if(post)
console.log(post.shortcode);
else
console.error(err);
}, {
interval,
lastPostShortcode,
fullPosts
});
```
but ther is no `shortcode` in `post`, so `post.shortcode === undefined` is always true
but there is `post.link`
I just have another issue, but it's not critical for me. I tried using the functions subscribeUserPosts() for a private user but it does not work. The function getProfile() shows lastPosts: null for a private user I should be following.
Maybe I am doing things wrong.
Anyways thanks!
I just have another issue, but it's not critical for me. I tried using the functions `subscribeUserPosts()` for a private user but it does not work. The function `getProfile()` shows `lastPosts: null` for a private user I should be following.
Maybe I am doing things wrong.
Anyways thanks!
constInsta=require("scraper-instagram");constjson=require('./config.json');sessionid=json.instaSessionid;constInstaClient=newInsta();username="ljrdiscordbot"//test account that I made
InstaClient.authBySessionId(sessionid).then(account=>console.log(account)).catch(err=>console.error(err));// InstaClient.getProfile(username)
// .then(profile => console.log(profile))
// .catch(err => console.error(err));
// InstaClient.subscribeUserPosts(username, (post, err) => {
// if (post)
// console.log(post);
// else
// console.error(err);
// }, {
// interval: 30,
// fullPosts: true
// });
InstaClient.getPost("CG3FrMnrTUKObPfAIVaAS1OeikUyHS-enHipUE0")//random shortcode from ljrdiscordbot
.then(post=>console.log(post)).catch(err=>console.error(err));InstaClient.getProfile(username).then(profile=>console.log(profile)).catch(err=>console.error(err));
it prints
{
first_name: 'Discord Group LJR',
last_name: '',
email: 'email@email.com',
is_email_confirmed: true,
is_phone_confirmed: false,
username: 'username',
phone_number: '',
gender: 3,
birthday: '',
fb_birthday: null,
biography: 'yes',
external_url: '',
chaining_enabled: true,
presence_disabled: false,
business_account: false,
usertag_review_enabled: false,
custom_gender: '',
trusted_username: 'username',
trust_days: 14,
profile_edit_params: {
username: {
should_show_confirmation_dialog: false,
is_pending_review: false,
confirmation_dialog_text: "Because your account reaches a lot of people, your username change may need to be reviewed. If so, you'll be notified when we've reviewed it. If not, your username will change immediately.",
disclaimer_text: ''
},
full_name: {
should_show_confirmation_dialog: false,
is_pending_review: false,
confirmation_dialog_text: "Because your account is verified, your name change may need to be reviewed. If so, you'll be notified when we've reviewed it. If not, your name will change immediately.",
disclaimer_text: ''
}
}
}
{
id: '42512582230',
name: '',
pic: 'https://scontent-nrt1-1.cdninstagram.com/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-nrt1-1.cdninstagram.com&_nc_ohc=qr8CH9GVPs4AX80bE1R&oh=c395c2d0ae3040bfe21d1d6967b083e8&oe=5FC1B28F&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2',
bio: '',
private: true,
access: false,
verified: false,
website: null,
followers: 2,
following: 0,
posts: 4,
lastPosts: null,
link: 'https://www.instagram.com/ljrdiscordbot',
user: {
mutualFollowers: [],
blocking: false,
blocked: false,
requesting: false,
requested: false,
following: false,
followed: false
}
}
TypeError: Cannot read property 'edges' of undefined
at D:\admin\Documents\Code\JS\temp test\node_modules\scraper-instagram\index.js:290:46
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```js
const Insta = require("scraper-instagram");
const json = require('./config.json');
sessionid = json.instaSessionid;
const InstaClient = new Insta();
username = "ljrdiscordbot"//test account that I made
InstaClient.authBySessionId(sessionid)
.then(account => console.log(account))
.catch(err => console.error(err));
// InstaClient.getProfile(username)
// .then(profile => console.log(profile))
// .catch(err => console.error(err));
// InstaClient.subscribeUserPosts(username, (post, err) => {
// if (post)
// console.log(post);
// else
// console.error(err);
// }, {
// interval: 30,
// fullPosts: true
// });
InstaClient.getPost("CG3FrMnrTUKObPfAIVaAS1OeikUyHS-enHipUE0")//random shortcode from ljrdiscordbot
.then(post => console.log(post))
.catch(err => console.error(err));
InstaClient.getProfile(username)
.then(profile => console.log(profile))
.catch(err => console.error(err));
```
it prints
```
{
first_name: 'Discord Group LJR',
last_name: '',
email: 'email@email.com',
is_email_confirmed: true,
is_phone_confirmed: false,
username: 'username',
phone_number: '',
gender: 3,
birthday: '',
fb_birthday: null,
biography: 'yes',
external_url: '',
chaining_enabled: true,
presence_disabled: false,
business_account: false,
usertag_review_enabled: false,
custom_gender: '',
trusted_username: 'username',
trust_days: 14,
profile_edit_params: {
username: {
should_show_confirmation_dialog: false,
is_pending_review: false,
confirmation_dialog_text: "Because your account reaches a lot of people, your username change may need to be reviewed. If so, you'll be notified when we've reviewed it. If not, your username will change immediately.",
disclaimer_text: ''
},
full_name: {
should_show_confirmation_dialog: false,
is_pending_review: false,
confirmation_dialog_text: "Because your account is verified, your name change may need to be reviewed. If so, you'll be notified when we've reviewed it. If not, your name will change immediately.",
disclaimer_text: ''
}
}
}
{
id: '42512582230',
name: '',
pic: 'https://scontent-nrt1-1.cdninstagram.com/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-nrt1-1.cdninstagram.com&_nc_ohc=qr8CH9GVPs4AX80bE1R&oh=c395c2d0ae3040bfe21d1d6967b083e8&oe=5FC1B28F&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2',
bio: '',
private: true,
access: false,
verified: false,
website: null,
followers: 2,
following: 0,
posts: 4,
lastPosts: null,
link: 'https://www.instagram.com/ljrdiscordbot',
user: {
mutualFollowers: [],
blocking: false,
blocked: false,
requesting: false,
requested: false,
following: false,
followed: false
}
}
TypeError: Cannot read property 'edges' of undefined
at D:\admin\Documents\Code\JS\temp test\node_modules\scraper-instagram\index.js:290:46
at processTicksAndRejections (internal/process/task_queues.js:97:5)
```
Are you coding JS for the first time ?
The issue is that all your requests are executed at the same time without waiting for each other.
Here you go :
```js
const
{ instaSessionid: sessionId } = require('./config'),
shortcode = 'CG3FrMnrTUKObPfAIVaAS1OeikUyHS-enHipUE0',
username = 'ljrdiscordbot';
const Insta = require('scraper-instagram');
const InstaClient = new Insta();
InstaClient
.authBySessionId(sessionId)
.then(account => {
console.log(account);
InstaClient
.getPost(shortcode)
.then(console.log)
.catch(console.error);
InstaClient
.getProfile(username)
.then(console.log)
.catch(console.error);
})
.catch(console.error);
```
Yeah thank you very much!
I'm pretty new to programming in general and I try to learn everything alone(no ones teaches me how to do it).
Now seeing your answer it seems logical. Does it have something to do with async functions? I think I need to learn the syntax :)
Yeah thank you very much!
I'm pretty new to programming in general and I try to learn everything alone(no ones teaches me how to do it).
Now seeing your answer it seems logical. Does it have something to do with async functions? I think I need to learn the syntax :)
I get these errors when i'm trying to subscribe with the function subscribeUserPosts().
When I start the program I get this error once:
And then I get this when the account that i want to subscribe to has posted something:
I don't really know what's happening
At
index.js:437
:The error :
As the documentation stipulates :
And :
Conclusion : the subscribed profile is private and either you are not logged in to your Instagram account or you are not following the subscribed profile.
Yes, thank you for responding so quick.
But I checked before if I was logged in and if I followed the account I wanted to "subrscribe" to. In fact even logged in, I can't use
subscribeUserPosts()
for any private account. Even though I am logged in.I can see my profile with the this: ...but the error is still the same
I checked everything and the error didn't change.
I also discovered two other things:
When I try to "subscribe" to a public account it seems to work at first, but then when a new post is detected, I just get
undefined
in the console instead of the post information.The shortcodes for private accounts are not supported in the
getPost()
function. I i try, I one of the errors I got yesterday:Thanks for the time and help!
Alright, investigating now.
Regarding subscribing public profiles though, I have a Discord bot running 24/7 which is simultaneously subscribed to 3 profiles and reposting their posts on a public community server, and it's been working fine for months now.
Although I can't reproduce the public profile issue, I can reproduce the
getPost()
issue with private profiles.Working on it.
So, I actually forgot a very small detail xD (
44b34d59
)Accessing post from followed private profiles is now working.
Ok I just found out why I couldn't get the posts. It was dumb from me: In the documentation and in my code, for
subscribeUserPosts()
, there was:but ther is no
shortcode
inpost
, sopost.shortcode === undefined
is always truebut there is
post.link
Okay, feel free to close this issue if everything is fixed. :)
Then, I'll make an NPM release.
I just have another issue, but it's not critical for me. I tried using the functions
subscribeUserPosts()
for a private user but it does not work. The functiongetProfile()
showslastPosts: null
for a private user I should be following.Maybe I am doing things wrong.
Anyways thanks!
Did you try with the latest commit ?
Oh, you mean no access while logged in?
That's very weird.
Can you show me the code?
it prints
I used the last commit
Are you coding JS for the first time ?
The issue is that all your requests are executed at the same time without waiting for each other.
Here you go :
Yeah thank you very much!
I'm pretty new to programming in general and I try to learn everything alone(no ones teaches me how to do it).
Now seeing your answer it seems logical. Does it have something to do with async functions? I think I need to learn the syntax :)
Yes, the async/await syntax is also useful.
But you need to learn about promises first.
Thanks!