twitter api v2 扩展字段选项 returns 比端点数据少

twitter api v2 expansion field option returns less data than the endpoint

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)

这就是我组织请求的方式,假设我希望从此端点获得的最大数据数是 20,我可以使用扩展字段来获取有关推文作者的其他数据,问题在于扩展字段负载与端点的默认数据 return 不匹配。例如,如果端点 returns 20 推文扩展字段也 returns 20 个字段,但在我的情况下有时我只得到 1,请提供任何帮助...

API 响应样本

  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}},

包括['用户]部分

{'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'},

当我尝试像这样检查两者的长度时,对于这个特定的响应,两个响应的长度应该是相等的。数据是 json 响应的名称。

len(data['data'])
>>100

同时

len(data['includes']['user'])
>>32

用户数据应该与每条推文相对应。

如果没有关于返回用户的更多详细信息,很难弄清这个问题的真相。

但是,我建议包 osometweet. It is currently in development, however, the search branch 有一个搜索方法,您可以使用您感兴趣的扩展参数将查询传递给该方法。

查看wiki,其中有很多说明。

那是因为推文数量不对应

如果假设某个用户在某些推文中很常见, 那么用户只出现一次。