我在Django中使用Google Calendars API,在哪里可以获得我的令牌和刷新令牌?

2024-04-19 01:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着做一些如下所示的事情。但是,我只能在开发者控制台上看到我的客户端ID和密钥。我不确定该令牌,但我尝试创建一个API密钥并将其传入。但是,我不知道从哪里获得刷新令牌。我已经包括了我的开发人员控制台的屏幕盖

我们正在使用django allauth,我知道您可以在django admin中设置社交帐户令牌,这就是我需要做的吗

 from google.auth.transport.requests import Request
    from google.oauth2.credentials import Credentials
    
creds = Credentials(
    token='token here',
    refresh_token='refresh token here',
    scopes=['scopes', 'listed', 'here'],
    token_uri='https://accounts.google.com/o/oauth2/token',

    client_id='client_id',
    client_secret='client secret'
)
creds.expiry = timezone.make_naive(self.token.expires_at)
if not creds.valid or creds.expired:
    creds.refresh(Request())

enter image description here


Tags: djangofromimportclienttokenidhererequest