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

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

Open
a-burlakovv opened this issue Aug 5, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@a-burlakovv
Copy link

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);
@junhoyeo junhoyeo added the bug Something isn't working label Aug 16, 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