user_data = 'user.fields=description,location,name,public_metrics,username,verified'
expand = 'expansions=author_id'
tag = 'new zealand -is:retweet'
url = "https://api.twitter.com/2/tweets/search/recent?query={}&{}&{}".format(tag, expand, user_data)
so this is the way I organized my request, let say the maximum number of data I want from this endpoint is 20, I can use the expansion field to get additional data about the tweet author, the problem is the expansion field payload does not match the default data return by the endpoint. for example, If the endpoint returns 20 tweets the expansion field also returns 20 fields, but in my case sometimes I get just 1, any help, please…
API response sample
data part
{'data': [{'id': '1341144983215239170',
'lang': 'en',
'created_at': '2020-12-21T22:14:15.000Z',
'text': "@chrissy99912291 Is it because he's neo? When DJ cuppy said she needs iPhone 12 no one dragged her, why y'all pressed? What kind of mentality is this?",
'author_id': '1268532525321932803',
'public_metrics': {'retweet_count': 0,
'reply_count': 0,
'like_count': 0,
'quote_count': 0}},
include[‘user] part
{'username': 'AOmozoya',
'description': "I'm gifted",
'id': '1102564893071429633',
'verified': False,
'location': 'xx, xx,
'public_metrics': {'followers_count': 64,
'following_count': 383,
'tweet_count': 608,
'listed_count': 0},
'name': 'Special_miracle'},
the length of the two response was supposed to be equal for this particular response when i try to check the length of both like this. data is the name of the json response.
len(data['data'])
>>100
whiles
len(data['includes']['user'])
>>32
user data is supposed to correspond with each tweets.
2
Answers
It is hard to get to the bottom of this issue without more details on the users that are returned.
However, I would recommend the package
osometweet
. It is currently in development, however, the search branch has a search method which you can pass your query to with the expansion parameters that you’re interested in.Check out the wiki which has a lot of instructions.
That’s because it does not correspond to the number of tweets.
If suppose, a user is common in some of the tweets,
then user is present only once.