Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Issue with getUserFollowers method in threads-api version 1.6.3 #286

Open
a-burlakovv opened this issue Jul 27, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@a-burlakovv
Copy link

a-burlakovv commented Jul 27, 2023

Hello,

I've been using your threads-api library for a project and I've encountered an issue with the getUserFollowers method. I'm currently using version 1.6.3 of the library.

Here's the script I'm using:

import pkg from 'threads-api';
import fs from 'fs';
const { ThreadsAPI } = pkg;

const threadsAPI = new ThreadsAPI({
  username: 'my_username',
  password: 'my_password',
  deviceID: 'android-2tjieqf5r9w00000'
});

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

const main = async () => {
  let cursor = null;
  let followers = [];

  const myID = await threadsAPI.getUserIDfromUsername('my_username');

  const { users: myFollowers, next_max_id } = await threadsAPI.getUserFollowers(myID);
  cursor = next_max_id;

  for (const follower of myFollowers.slice(0, 20)) {
    let followerCursor = null;
    let followerFollowers = [];
    do {
      const { users, next_max_id } = await threadsAPI.getUserFollowers(follower.user_id, followerCursor);
      followerFollowers = followerFollowers.concat(users.map(user => user.username));
      followerCursor = next_max_id;

      console.log(`Collected ${followerFollowers.length} followers. Waiting 10 seconds before the next followers request...`);
      await delay(10000);
    } while (followerCursor && followerFollowers.length < 500);

    followers = followers.concat(followerFollowers);
    console.log(`Finished collecting followers for ${follower.username}. Total followers collected: ${followers.length}. Waiting 10 seconds before the next user...`);
    await delay(10000);
  }

  fs.writeFileSync('followers.json', JSON.stringify(followers));
};

main().catch(console.error);

When I run this script, I get the following error:

TypeError: Cannot read properties of null (reading 'maxID')

It seems like the getUserFollowers method is not working as expected. I've checked the documentation and my usage appears to be correct. Could you please help me understand what might be going wrong here?

I'm running the script from the root directory of the project, so there should be no issues with versioning or accessing the correct methods.

Thank you for your time and assistance.

@a-burlakovv
Copy link
Author

Maybe someone just have a script following followers of my followers?))) Feeling kinda stupid, because i don't see other people struggle with this))

@junhoyeo junhoyeo added the bug Something isn't working label Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants