简体   繁体   English

Twitter API 版本 2 不适用于 OAuth 1

[英]Twitter API version 2 not working with OAuth 1

I used to get Tweet data using API version 1.1 like below:我曾经使用 API 1.1 版获取 Tweet 数据,如下所示:

import requests
from requests_oauthlib import OAuth1

oauth = OAuth1(consumer_key, consumer_secret, access_token, token_secret)
requests.get('https://api.twitter.com/1.1/statuses/show.json?id=<TWEET_ID>', auth=oauth)

It's working properly, and there is no issue at all.它工作正常,完全没有问题。 Now I tried to do the same thing with Twitter API version 2, but it returns 401/unauthorized现在我尝试用 Twitter API 版本 2 做同样的事情,但它返回 401/unauthorized

The endpoint is requests.get('https://api.twitter.com/2/tweets/<TWEET_ID>', auth=oauth)端点是requests.get('https://api.twitter.com/2/tweets/<TWEET_ID>', auth=oauth)

Could someone already try Twitter version 2 successfully?有人可以成功试用 Twitter 版本 2 吗? Could you tell me what I need to change?你能告诉我我需要改变什么吗? From Twitter documentation, I could use the same OAuth 1.0 for API version 2.从 Twitter 文档中,我可以对 API 版本 2 使用相同的 OAuth 1.0。

I found the reason, my app is standalone app, so I could not use Twitter api version 2我找到了原因,我的应用程序是独立应用程序,所以我无法使用 Twitter api 版本 2

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM