Hello,
I have set up an application and with the helpt of the bearer Token and this help:
github .com/twitterdev/Twitter-API-v2-sample-code/blob/master/User-Tweet-Timeline/user_tweets.js
i am trying to write a custom news bot for our small discord server. So he reads the newest tweets from some Users and post the links in the Discord Chat.
But i am only able to get the Tweets of TwitterDev.
I tried it with the JS Example above, of course with my own bearer token but… i dont get an error and i dont get a response.
I only can read the Timeline of TwitterDev
It sure is something stupid… what did i miss?
What user or users are you trying to read? What’s the full request you’re making and what’s the exact response from the API?
For Test purposes i try to read user:
1072404907230060544
and this is my function:
const userId = 1072404907230060544; //genshinimpact
const url = `https://api.twitter.com/2/users/${userId}/tweets`;
const getUserTweets = async () => {
let userTweets = [];
// we request the author_id expansion so that we can print out the user name later
let params = {
"max_results": 20,
"tweet.fields": "created_at",
"expansions": "author_id"
}
const options = {
headers: {
"User-Agent": "80sChildNews",
"Authorization": `Bearer ${bearerToken}`
}
}
let hasNextPage = true;
let nextToken = null;
let userName;
console.log("Read Tweets...");
try {
while (hasNextPage) {
let resp = await getPage(params, options, nextToken);
if (resp && resp.meta && resp.meta.result_count && resp.meta.result_count > 0) {
userName = resp.includes.users[0].username;
if (resp.data) {
userTweets.push.apply(userTweets, resp.data);
}
if (resp.meta.next_token) {
nextToken = resp.meta.next_token;
} else {
hasNextPage = false;
}
} else {
hasNextPage = false;
}
//for now, only one Page
hasNextPage = false;
}
} catch (err) {
logToDev(`Request failed: ${err}`);
}
console.log(userTweets);
console.log(`Got ${userTweets.length} Tweets from ${userName} (user ID ${userId})!`);
}
and the output is only:
Read Tweets...
[ ]
Got 0 Tweets from undefined (user ID 1072404907230060500)!
I am sure my Bearer Code is correct. I dont get any ErrorMessages
thats why i am stuck
my primary language is not JS sorry 
1 Like
const userId = 1072404907230060544;
undefined (user ID 1072404907230060500)!
Javascript has problems with 64bit integers, you have to specify those as strings Twitter IDs | Docs | Twitter Developer Platform like
const userId = "1072404907230060544";
1 Like
That was it. thank you very much!
And that, kids, is why you should learn the language from the basics…
2 Likes