如何使用 rauth 使推特持有者令牌无效



如何使用 rauth 使来自 Twitter 的持有者令牌无效?(https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token)

我尝试通过 oauth2 会话执行此操作,但它不起作用。顺便问一下,有没有办法查看将由 rauth 发送/创建的完整请求?这对于调试和了解 rauth 产生的内容非常有帮助。

这是我到目前为止的代码:

session = rauth.OAuth2Session(client_id=c_key,
                              client_secret=c_secret,
                              access_token=o_bearer_token)
bearer_raw = session.post('https://api.twitter.com/oauth2/invalidate_token',
                           params={ 'Host': 'api.twitter.com',
                                            'User-Agent': '',
                                            'Accept': '*/*',
                                            'Content-Type': 'application/x-www-form-urlencoded',
                                            'Content-Length': str(len(o_bearer_token)),
                                            'access_token':str(o_bearer_token)})

我认为请求的格式不正确。看起来Twitter文档表明它应该是这样的:

session = rauth.OAuth2Session(client_id=KEY,
                              client_secret=SECRET,
                              access_token=TOKEN)
r = session.post('https://api.twitter.com/oauth2/invalidate_token', bearer_auth=True)

顺便说一下,Rauth 是 Requests;它只是 Requests 之上的一层。所以是的,您可以像查看请求一样查看请求。像r.request这样的东西应该暴露你正在寻找的东西。

相关内容

最新更新