python social auth twitter 403后跟220

时间:2019-02-22 08:41:57

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

我正在尝试使用Python social从Android授权,我正在以以下格式传递令牌: “ xxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” 设置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', '')

但是只要它在方法:user_data上到达Twitter后端类,即调用Twitter的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(红宝石应用程序)的帮助下进行了手动测试

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上

显示成功的图像:

Insomnia test reqyest

问题: 我需要扩展Twitter后端并传递token_secret参数吗?如何实现?

1 个答案:

答案 0 :(得分:0)

解决方案

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-urlencode发送可根据Android应用的需要进行操作。