【发布时间】:2022-10-01 07:58:15
【问题描述】:
我正在使用tweepy4.10.1 来获取使用StreamingClient 的推文,但我无法加载任何media 信息甚至includes 对象本身。我已经使用get_tweet() 方法尝试了类似的代码,media 和includes 收到了很好的结果。
编码:
class TweetPrinter(tweepy.StreamingClient):
def on_tweet(self, tweet):
print(tweet.includes)
streaming_client = TweetPrinter(\'bearer-token\')
streaming_client.add_rules(tweepy.StreamRule(\"from:xxxyyy\"))
streaming_client.filter(tweet_fields=[\'author_id\', \'created_at\'],
media_fields=[\'preview_image_url\', \'url\'],
expansions=[\'attachments.media_keys\'])
print(tweet.includes)
我收到以下错误:
raise AttributeError from None
当我通过get_tweet() 方法使用相同的推文ID 时,我可以从includes 很好地检索media。
client = tweepy.Client(config.BEARER)
ID = \'xxxxyyyy\'
tweet = client.get_tweet(ID,
tweet_fields=[\'author_id\', \'created_at\'],
media_fields=[\'preview_image_url\', \'url\'],
expansions=[\'attachments.media_keys\'])
print(tweet.includes)
根据谷歌,官方文档和常见问题解答,我已经尝试了我发现的所有推荐步骤
- Why am I not getting expansions or fields data with API v2 using Client?
-
tweepy.StreamingClient.filter 允许
media_fields和expansions - Tweepy does not return url media field while using Twitter API v2 methods
-
tweepy.StreamingClient.on_includes 这表明
includes应该可用
我在这里想念什么?
标签: python python-3.x twitter tweepy