Open alexduca opened 3 years ago
Hey,
You have a variable has_next_page
that inform you if you can change your page to end_cursor
(next page of follower).
The first
parameters is limited to 50, it's the number of followers per pages.
Here it is a sinple code to list all your followers :
(async () => {
//List of all Followers Name
let myFollowers = []
let myId = "myUserId"
let followers = await client.getFollowers({ userId: myId })
//get your followers on the first page
let nextPage = followers.page_info.has_next_page
//true if you have an other page of followers
let cursor = followers.page_info.end_cursor
//next page of follower
addFollowersName(followers.data)
//loop to navigate into all the pages of followers
while(nextPage) {
followers = await client.getFollowers({ userId: id, first: 50, after: cursor})
nextPage = followers.page_info.has_next_page
cursor = followers.page_info.end_cursor
addFollowersName(followers.data)
}
console.log(`List of all my Followers : ${myFollowers.join("\n- ")}`)
})
I want get all my followers list but i get only the first 50 results... after that i get this error
(node:8088) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined at C:\Users\ducaa\Desktop\pupp\test.js:32:51 at emitUnhandledRejectionWarning (internal/process/promises.js:168:15) at processPromiseRejections (internal/process/promises.js:247:11) at processTicksAndRejections (internal/process/task_queues.js:94:32) (node:8088) TypeError: Cannot read property 'username' of undefined at C:\Users\ducaa\Desktop\pupp\test.js:32:51 (node:8088) [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. at emitDeprecationWarning (internal/process/promises.js:180:11) at processPromiseRejections (internal/process/promises.js:249:13) at processTicksAndRejections (internal/process/task_queues.js:94:32)
THIS IS THE CODE