Ban*_*ani 3 python twitter tweepy twitterapi-python
即使我的帐户处于活动状态,我也无法使用我的 Twitter 开发者帐户进行身份验证
\nimport tweepy\nconsumer_key= 'XX1'\nconsumer_secret= 'XX2'\naccess_token= 'XX3'\naccess_token_secret= 'XX4'\nauth = tweepy.OAuthHandler(consumer_key, consumer_secret)\nauth.set_access_token(access_token, access_token_secret)\napi = tweepy.API(auth)\napi.update_status("Hello Tweepy")\nRun Code Online (Sandbox Code Playgroud)\n我收到错误:
\nForbidden: 403 Forbidden\n\n453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you\xe2\x80\x99ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve\nRun Code Online (Sandbox Code Playgroud)\n开发者门户上没有从 Essential 升级到 Elevated 的选项。有什么建议吗?
\n在 OP 所指的情况下,他正在尝试发送推文,因此使用 Tweepy + Twitter API v2 的代码将如下所示:
import tweepy
client = tweepy.Client(consumer_key="",
consumer_secret="",
access_token="",
access_token_secret="")
# Replace the text with whatever you want to Tweet about
response = client.create_tweet(text='hello world')
Run Code Online (Sandbox Code Playgroud)
请记住,您的 access_token + access_token_secret 必须具有读写权限才能生成,以便能够发送推文(否则您将在之前的代码中收到 403 错误):

有关如何执行此操作的更多详细信息,请参阅https://twittercommunity.com/t/how-do-i-change-my-app-from-read-only-to-read-write/163624/4 。
我发现基本访问只能使用 Twitter API v2
代码应该是
import tweepy
consumer_key= 'x'
consumer_secret= 'xx'
access_token= 'xxx'
access_token_secret= 'xxxx'
client = tweepy.Client(consumer_key= consumer_key,consumer_secret= consumer_secret,access_token= access_token,access_token_secret= access_token_secret)
query = 'news'
tweets = client.search_recent_tweets(query=query, max_results=10)
for tweet in tweets.data:
print(tweet.text)
Run Code Online (Sandbox Code Playgroud)
感谢 https://twittercommunity.com/t/403-forbidden-using-tweepy/162435/2
| 归档时间: |
|
| 查看次数: |
23781 次 |
| 最近记录: |