Skip to content
This repository was archived by the owner on Sep 8, 2023. It is now read-only.
This repository was 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

Description

@a-burlakovv

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions