我想请求一个令牌,以便我的 Postman 可以登录我的 Gmail 帐户,然后我可以调用 Google Cloud API。
我正在尝试输入我的 Gmail 电子邮件地址及其密码,如您从这张图片中看到的
最终目标是获得这样的 API
https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards
我可以通过从 gcloud 登录我的 Gmail 帐户(“gcloud auth application-default login”),然后使用 gcloud auth application-default print-access-token 打印令牌,复制打印的令牌并将其粘贴到访问令牌中(邮差)。嗯,它有效,但它有点迫使我启动 gcloud 并安装它。我很确定我可以通过与登录 gcloud 的同一用户进行签名来达到相同的想法。我只是不知道如何与邮差一起做。我过去几个小时读到的所有内容都让我看到了上面粘贴的图像,但由于这个问题的错误,它失败了。
如果相关的话,这是我获取令牌的 gcloud 控制台
C:\Program Files (x86)\Google\Cloud SDK>gcloud auth application-default print-access-token
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\lib\third_party\google\auth\_default.py:69: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
ya29.a0Ae4lvC3-3WxUmx... removed token ... hs251yTql3eEE
C:\Program Files (x86)\Google\Cloud SDK>
*** 首次发布后进行了一些编辑
其他暂定结果是
Erro 400: invalid_request
Invalid parameter value for redirect_uri: Missing scheme: /
当我尝试时
我从中复制的客户端 ID
*** 根据Madhead的建议进行编辑
我仔细遵循了建议的所有步骤,实际上我可以通过单击“获取新访问令牌”直接从 Postman 获取 Google 令牌。尽管如此还是得到了
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}
对于 Postman 的这两个尝试(粘贴了 curl 脚本,因为它比 Postman 打印屏幕更容易从其他人那里进行评估)
curl --location --request GET 'https://monitoring.googleapis.com/v1/projects/firetestjimis/dashboards' --header 'Authorization: Bearer ya29. *** token *** kO3Fg'
curl --location --request POST 'https://firestore.googleapis.com/v1/projects/firetestjimis/databases/(default)/documents:runQuery' --header 'Authorization: Bearer ya29. *** token *** kO3Fg' --header 'Content-Type: application/json' --data-raw '{
"structuredQuery": {
"where" : {
"fieldFilter" : {
"field": {"fieldPath": "id"},
"op":"EQUAL",
"value": {"stringValue": "1"}
}
},
"from": [{"collectionId": "transfer"}]
}
}'
这是在中创建的 OAuth 客户端 ID凭证屏幕 https://console.cloud.google.com/apis/credentials?project=firetestjimis
{"web":{"client_id":"7953 *** 5k6e9ivtdg.apps.googleusercontent.com","project_id":"firetestjimis","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"IJGCe *** Du6bU","redirect_uris":["https://oauth.pstmn.io/v1/callback"]}}
下载自
And here is the
*** 已编辑
*** 已编辑
*** 成功添加两个范围后进行编辑
它说“因为您添加了敏感范围,所以您的同意屏幕在发布之前需要经过 Google 验证”
当我单击“提交进行验证”时,我看到它抱怨应用程序主页和应用程序隐私链接