【问题标题】:python social auth twitter 403 followed by 220python social auth twitter 403 后跟 220
【发布时间】:2019-07-16 07:31:24
【问题描述】:

我正在尝试使用 Python 社交从 Android 授权,我以以下格式传递我的令牌: “xxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” 设置 backend="twitter" 和 "grant_type":"convert_token"

我为 Facebook 做的事情和作品一样。

我得到了正确的设置

SOCIAL_AUTH_TWITTER_KEY = os.environ.get('SOCIAL_AUTH_TWITTER_KEY', '')
SOCIAL_AUTH_TWITTER_SECRET = os.environ.get('SOCIAL_AUTH_TWITTER_SECRET', '')

但每当它在方法中遇到 Twitter 后端类时:user_data 即调用 Twitters API verify_credentials.json 端点。

它崩溃并返回 400 响应,然后是:

{
  "error": "invalid_request",
  "error_description": "Backend responded with HTTP403: {\"errors\":[{\"message\":\"Your credentials do not allow access to this resource\",\"code\":220}]}."
}

我尝试手动重新创建东西,但同样的事情发生了。

我知道 10 月 31 日的 Twitter API 更改,我在 Twitter 的开发者面板中添加了回调 url,用于应用程序和实时/开发服务器。

twittersdk://
http://127.0.0.1:8000/auth/complete/twitter/

为了以防万一,我把权限改成了读+写,但没用

Access permission
Read, write, and direct messages
Additional permissions
Request email address

另外,我已经刷新了两次密钥和秘密,并小心地将它们放在后端和 Android 上。

在 2018 年 10 月 31 日之前,相同的设置可以正常工作,但突然之间没有任何效果。

我从 Android 调用:

TwitterCore.getInstance().getSessionManager().getActiveSession
                ().getAuthToken().token;

检索令牌。

Android 使用 https://api.twitter.com/1.1/account/verify_credentials.json 检索令牌

更新

我在 twurl (ruby app) 的帮助下手动测试了

twurl authorize -u 'myuser@gmail.com' -p 'mypassword' -c 'xxxxxxxxxxxxxxxxxxxxxxxxx' -s 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -a

然后在 ~/.twurlrc 中有一个 access_token(就像 Android 正在传递一样)。

但是,GET 请求 verify_credentials.json 需要 token_secret 以及我调试的属性,我不会从 Android 传递 convert_token

显示成功的图片:

问题: 我是否需要扩展 Twitter 后端并传递 token_secret 参数以及如何传递?

【问题讨论】:

    标签: android twitter django-rest-framework python-social-auth


    【解决方案1】:

    解决方案

    https://github.com/RealmTeam/django-rest-framework-social-oauth2/issues/15 这里说我需要通过 oauth_token_secret

     curl -X POST -d "grant_type=convert_token&client_id=<client_id>&backend=twitter&token=oauth_token=<token>%26oauth_token_secret=<secret_token>" http://localhost:8000/auth/api/convert-token
    

    在请求中将其作为 application/x-www-form-urlencoded 发送可以满足 Android 应用的需要。

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 2014-07-03
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多