首页 > 解决方案 > Twitter OAuth2 令牌撤销返回 401 错误,提示“不允许客户端应用程序使此令牌无效”。

问题描述

我可以获得 OAuth2 令牌,但无法撤销它。

重现错误:

let token_url = "https://api.twitter.com/oauth2/token";
let revoke_url = "https://api.twitter.com/oauth2/invalidate_token"
let auth = {
    username: CLIENT_API_KEY,
    password: CLIENT_API_SECRET_KEY
}
axios.post(token_url, "grant_type=client_credentials", { auth })
.then( response => {
    let access_token = response.data["access_token"]
    axios.post(revoke_url, `access_token=${access_token}`, { auth })
    .then( response => {
        console.log("REVOKE SUCCESS")
        console.log(response)
    })
    .catch( e=> {
        console.log("Failed to revoke")
        console.log(e.response.data)
    })
})

然后我得到

Failed to revoke
{ errors:
   [ { code: 348,
       message:
        'Client application is not permitted to to invalidate this token.' } ] }

尝试谷歌搜索,但代码 348 和消息中没有任何内容。http 错误代码是401 (unauthorized).

我永远无法撤销我的 OAuth2 令牌。帮助。

标签: twitteroauth-2.0axiostwitter-oauth

解决方案


推荐阅读