Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python api v1.1中的单用户OAuth错误_Python_Twitter - Fatal编程技术网

Python api v1.1中的单用户OAuth错误

Python api v1.1中的单用户OAuth错误,python,twitter,Python,Twitter,我无法使用Twitter api进行身份验证。我使用Python中的oauth2模块进行单用户登录 我一直在使用以下函数请求跟随者ID: import oauth2 as oauth def oauth_req(url, key, secret, http_method="GET", post_body=None, http_headers=None): consumer = oauth.Consumer(key=key, secret=secret) token = oaut

我无法使用Twitter api进行身份验证。我使用Python中的oauth2模块进行单用户登录

我一直在使用以下函数请求跟随者ID:

import oauth2 as oauth

def oauth_req(url, key, secret, http_method="GET", post_body=None, http_headers=None):
    consumer = oauth.Consumer(key=key, secret=secret)
    token = oauth.Token(key=key, secret=secret)
    client = oauth.Client(consumer, token)
    resp, content = client.request(
        url,
        method=http_method,
    )
    return content
然后,我将从一个名为twitter_auth.py的文档运行它,如下例所示:

ids = twitter_auth.oauth_req('https://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=marksandspencer', 'CONSUMER_KEY', 'CONSUMER_SECRET')
然后它只返回以下内容:
“{”错误“:[{”消息“:“无效或过期的令牌”,“代码”:89}]}”

我似乎无法让它工作,我的应用程序细节是好的,没有过期-所以我假设他们可能在某种程度上是无效的-我只是不知道如何


提前感谢。

您传入的是消费者密钥和消费者密钥,但不是令牌密钥和令牌密钥,因此您的令牌变量使用的凭据与消费者相同。需要通过您的代码或在Twitter网站上手动请求访问令牌凭据