【发布时间】:2022-01-04 03:21:49
【问题描述】:
我尝试使用 tweepy 和 TwitterAPI,但这两种解决方案都不起作用,因为我拥有 Twitter 开发者帐户的基本访问权限,并且没有提升权限(提升权限的应用程序被拒绝)。
基本上在做:
- tweepy:
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# set access to user's access key and access secret
auth.set_access_token(access_token, access_token_secret)
# calling the api
api = tweepy.API(auth)
# the ID of the status
id = 1272771459249844224
# fetching the status
status = api.get_status(id)
# fetching the text attribute
text = status.text
- 推特 API:
r = api.request('statuses/show/:%d' % 210462857140252672)
print(r.text)
这两种解决方案都不起作用。我认为所有包含访问密钥的解决方案都行不通。
我也尝试了一些网络抓取,但它也不起作用。这是我尝试过的:
from lxml import html
import requests
page = requests.get('https://twitter.com/UniteAlbertans/status/572342978255048705')
print(page.text)
tree = html.fromstring(page.content)
tree.xpath('//span[@class="css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0"]/text()')
但我认为这不起作用,因为当我打印页面文本时,我什至看不到推文的文本。
有人可以帮我如何通过代码获取给定推文 ID 的推文文本吗?
非常感谢:)
【问题讨论】:
-
请尝试使用您在实际代码中使用的相同 python 语法(纯文本)再次编辑问题。这些行
//是无效的python 语法 -
@chickitychinachinesechicken 完成
-
运行我使用
print(status.text)的tweepy 代码并得到Which movie did you watch recently? Reply us! . . . . . #tuesdaymood #TuesdayThoughts #Bollywood #Hollywood #genre #movies #movie #fun -
我无权访问 Twitter Developer Elevated 帐户,我只有必要的访问权限。我收到一条错误消息: TweepError: [{'message': '您当前拥有基本访问权限,其中仅包括对 Twitter API v2 端点的访问权限。如果您需要访问此端点,则需要通过 Developer Portal 申请提升访问权限。您可以在这里了解更多信息:developer.twitter.com/en/docs/twitter-api/getting-started/…', 'code': 453}]。我申请了提升访问权限,但被拒绝了 :( 是的,这是预期的输出
-
嗯,好吧,我对此一无所知,看来这可能不是编码问题,而更像是 Twitter 开发者帐户问题...
标签: python web-scraping twitter tweepy twitterapi-python