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);
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:
usernames.json
).searchUsers
method to search for each username.Here's a code snippet that demonstrates how I'm using the
searchUsers
method: