【发布时间】:2022-01-27 08:14:02
【问题描述】:
我在对象 obj 中获取了该用户的推文和相应的 id。我想知道为什么我没有得到像conversation_id 这样的其他信息。我想用它来获取回复和报价。这是我在互联网上找到的解决方案,但不知道如何使其工作。
有谁知道提取conversation_id 或任何其他参数,如geo.place_id?我正在使用 tweepy,但如果有人有任何其他解决方案使用另一个库来获得相同的结果,它也会有所帮助。谢谢你的帮助!!!
如果您创建另一个文件配置并定义您的令牌,您可以尝试该代码。出于安全考虑,我不能分享我的。
import tweepy
import config
users_name = ['derspiegel', 'zeitonline']
tweet_tab = []
def getClient():
client = tweepy.Client(bearer_token=config.BEARER_TOKEN,
consumer_key=config.API_KEY,
consumer_secret=config.API_KEY_SECRET,
access_token=config.ACCESS_TOKEN,
access_token_secret=config.ACCESS_TOKEN_SECRET)
def searchTweets(client):
for i in users_name:
client = getClient()
user = client.get_user(username=i)
userId = user.data.id
tweets = client.get_users_tweets(userId,
expansions=[
'author_id', 'referenced_tweets.id', 'referenced_tweets.id.author_id',
'in_reply_to_user_id', 'attachments.media_keys', 'entities.mentions.username', 'geo.place_id'],
tweet_fields=[
'id', 'text', 'author_id', 'created_at', 'conversation_id', 'entities',
'public_metrics', 'referenced_tweets'
],
user_fields=[
'id', 'name', 'username', 'created_at', 'description', 'public_metrics',
'verified'
],
place_fields=['full_name', 'id'],
media_fields=['type', 'url', 'alt_text', 'public_metrics'])
if not tweets is None and len(tweets) > 0:
obj = {}
obj['id'] = userId
obj['text'] = tweets
tweet_tab.append(obj)
return tweet_tab
searchTweets(client)
print("tableau final", tweet_tab)
【问题讨论】:
标签: python python-3.x twitter tweepy