-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User fields not returning any data #83
Comments
I was able to resolve this by taking this approach const params = {
query:'"happiness is" -sad -worst -sucks -never -bad -http -https -disappointing -is:retweet lang:en -has:mentions -has:hashtags',
expansions:'author_id',
max_results:30,
user:{
fields: ['username', 'profile_image_url']
}
}
const response = await client.get('tweets/search/recent', params)
const tweets = response.data
tweets.forEach((tweet, i) => {
const user = response.includes.users[i]
if(tweet.text.match(/^happiness is /i)){
if(!tweet.text.includes('\n')){
const fullTweet = {
tweet,
user
}
console.log(fullTweet)
}
}
}); which gives the desired output {
tweet: {
author_id: '1371394636846002181',
id: '1398991509907677184',
text: 'Happiness is not in the mere possession of money; it lies in the joy of achievement, in the thrill of creative effort.'
},
user: {
profile_image_url: 'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png',
name: 'dfbe443',
id: '1371394636846002181',
username: 'dfbe443'
}
} however If this is the needed approach I feel as if it should be in the readme |
@BrandonLeffew I believe this is the expected behavior of the Twitter V2 API itself. Almost all fields are now 'opt-in', so you no longer get more data than you request, unless you request it. See The New Twitter API v2 > Fundamentals > Expansions
For reference, the code in your 'fixed' request that does this is: user:{
fields: ['username', 'profile_image_url']
} You don't need to do the transformation from {
"data": {
"attachments": {
"media_keys": [
"16_1211797899316740096"
]
},
"author_id": "2244994945",
"id": "1212092628029698048",
"referenced_tweets": [
{
"type": "replied_to",
"id": "1212092627178287104"
}
],
"text": "We believe the best future version of our API will come from building it with YOU. Here’s to another great year with everyone who builds on the Twitter platform. We can’t wait to continue working with you in the new year. https://t.co/yvxdK6aOo2"
},
"includes": {
"media": [
{
"media_key": "16_1211797899316740096",
"type": "animated_gif"
}
],
"users": [
{
"id": "2244994945",
"name": "Twitter Dev",
"username": "TwitterDev"
}
],
"tweets": [
{
"author_id": "2244994945",
"id": "1212092627178287104",
"referenced_tweets": [
{
"type": "replied_to",
"id": "1212092626247110657"
}
],
"text": "These launches would not be possible without the feedback you provided along the way, so THANK YOU to everyone who has contributed your time and ideas. Have more feedback? Let us know ⬇️ https://t.co/Vxp4UKnuJ9"
}
]
}
} |
Prerequisites
following:
Description
Attempting to get the username of a tweet author doesn't return information but also doesn't return an error
Steps to Reproduce
Expected behavior:
return user fields in console log
Actual behavior:
Reproduces how often:
100%
Versions
latest
Additional Information
N/A
The text was updated successfully, but these errors were encountered: