junhoyeo / threads-api

Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.
https://threads.junho.io
MIT License
1.58k stars 134 forks source link

Issue with searchUsers Method - Fails to Find Users and Returns Undefined Error #298

Open a-burlakovv opened 11 months ago

a-burlakovv commented 11 months ago

I have been using the searchUsers method in the Threads API to search for users from a file. It was working as expected, but recently it has started failing to find users and returns an "undefined" error.

What I did:

  1. Read usernames from a file (e.g., usernames.json).
  2. Use the searchUsers method to search for each username.
  3. Observe the "undefined" error when the method fails to find users.

Here's a code snippet that demonstrates how I'm using the searchUsers method:

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

const threadsAPI = new ThreadsAPI({
  username: ' ',
  password: ' ',
});

function readUsernamesFromFile() {
  const fileContent = fs.readFileSync('usernames.json', 'utf-8');
  return JSON.parse(fileContent);
}

const main = async () => {
  const usernames = readUsernamesFromFile();

  for (const username of usernames) {
    try {
      const users = await threadsAPI.searchUsers(username, 1);
      if (users.num_results > 0) {
        console.log(`Found user: ${username}`);
      } else {
        console.log(`User ${username} not found`);
      }
    } catch (e) {
      console.log(`Error searching for ${username}: ${e}`);
    }
  }
};

main().catch(console.error);