使用 Expo SDK 刷新 Google API 访问令牌?

ljm*_*cic 6 javascript fetch google-oauth react-native expo

我遵循了Google login / Expo指南,并获得了访问令牌和刷新令牌。

但是在访问令牌到期后,我无法获得新令牌。

当我尝试获得新的时,出现此错误:

"error": "unauthorized_client", "error_description": "Unauthorized"

以下是用于获取新访问令牌的发送请求示例(Google 文档):

    POST /oauth2/v4/token HTTP/1.1
    Host: www.googleapis.com
    Content-Type: application/x-www-form-urlencoded

    client_id=<your_client_id>&
    client_secret=<your_client_secret>&
    refresh_token=<refresh_token>&
    grant_type=refresh_token
Run Code Online (Sandbox Code Playgroud)

PS我没有忘记替换client_id等相关数据。

eya*_*oli 1

必须使用获取刷新令牌的同一客户端 ID 来获取另一个访问令牌!

您可能在 Android 上使用此代码,对于移动设备,Google 不会向您提供秘密,因为不需要它。您可以从请求中删除密钥并更改客户端 ID 以匹配您的移动客户端 ID。