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
Description
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:
- Read usernames from a file (e.g.,
usernames.json
). - Use the
searchUsers
method to search for each username. - 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);