django - 我可以在哪里为 twitter 获取 access_token 和 token_secret

标签 django django-rest-framework django-rest-auth

也许我的问题很愚蠢。

但是我在rest-auth的官方文档和问题中都找不到答案。

我想通过 Twitter 使用身份验证。

我在 Twitter 上创建了应用程序,将所有数据放入模型社交应用程序中
根据我查看的文档:

from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
from rest_auth.views import LoginView
from rest_auth.social_serializers import TwitterLoginSerializer
from rest_framework.permissions import AllowAny


class TwitterLogin(LoginView):
    serializer_class = TwitterLoginSerializer
    adapter_class = TwitterOAuthAdapter
    permission_classes = (AllowAny,)

添加网址:
from django.urls import path

from .views import TwitterLogin


urlpatterns = [
    path('rest-auth/twitter/', TwitterLogin.as_view(), name='twitter_login')
]

然后去链接:
/休息认证/推特/
并得到了请求:
{
    "access_token": "",
    "token_secret": ""
}

IE。这些数据必须从前端传输到 API 端点。

问题是:前端将如何获取 acces_token 和 token_secret?

我不明白这一刻的身份验证。

如果某个地方有这个问题的详细描述,或者在这个资源上已经有人给出了这个问题的答案 - 我会很感激这个链接。

最佳答案

在您的 Twitter 应用程序中,您需要确保“允许此应用程序用于使用 Twitter 登录?”选项已启用。

然后您可以按照这些说明获取 token 和 token secret https://dev.twitter.com/web/sign-in/implementing .

allauth 文档中的相关部分:https://django-allauth.readthedocs.io/en/latest/providers.html#id2

关于django - 我可以在哪里为 twitter 获取 access_token 和 token_secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48319113/

相关文章:

django - 如何 JSON 序列化 Python 字典?

python - Apache 不提供 django 管理静态文件

python - 需要字段的 django rest 框架错误

python - 为什么网站匹配查询不存在?

django - 在 django-rest-auth 中有 "logout"端点有什么意义?

python - 删除特定 url 路径的身份验证和权限

python - views.py 和 urls.py 不连接来执行功能

python - 在哪里设置 DEFAULT_DB_ALIAS?

python - put() 至少需要 3 个参数(给定 2 个)

python - 我如何以编程方式注销用户?[Django]