tweepy/twitter api v2:免费获取推文

问题描述 投票:0回答:2

我正在尝试使用 tweepy 对 Twitter 的新 API (v2) 进行身份验证并检索推文,但遇到与身份验证过程相关的奇怪错误。

我目前正在使用免费访问 API。

代码示例:

import tweepy

# Authentification OAuth 1.0a User Context to retrieve my own data
dict_twitter_api = {
    "consumer_key": "blah",
    "consumer_secret": "blah",
    "access_token": "blah", 
    "access_token_secret": "blah"
}
client = tweepy.Client(**dict_twitter_api)

# If you're working behind a corporate proxy, 
# client.session.proxies = {
#    "http": "my-corporate-proxy", 
#     "https": "my-corporate-proxy", 
# }

print(client.get_me())  # <-- this works well

print(client.get_home_timeline())

回溯结果:

> Forbidden: 403 Forbidden
> When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.

我检查了我的不同令牌并确认 OAuth 1.0a 用户上下文身份验证应该工作以检索我自己的时间线。

python twitter tweepy
2个回答
0
投票

返回的异常其实与认证过程无关

Twitter 的免费 API 访问权限根本不允许您检索自己的时间线或事件推文。这在 关于 twitter API 文档页面中有说明;它还解释了为什么 rate limits 上的页面仅详细说明“基本”访问权限而没有提及“免费”访问权限...

注意:最终,这似乎是一个“与代码无关”的问题/答案;它可能仍然有用,因为 1) 这还没有得到足够的引用,并且 2) 当前的回溯会使任何开发人员走上错误的道路......鉴于这种情况,我还将分享 this resource 这可能是更新的/彻底。


0
投票

Musk 让这个 API 端点付费。

在 api v2 免费层中,您只能访问发布推文和 GET /2/users/me。

来源:https://developer.twitter.com/en

这是您可以从中获得的表格

/2/users/me

https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user

© www.soinside.com 2019 - 2024. All rights reserved.