Sai*_*Sai 56 google-api oauth-2.0 google-api-client postman google-oauth2
我正在尝试使用Postman Chrome应用程序访问Proximity Google API.我已经关注邮递员和谷歌开发网站的教程,但我仍然收到401错误消息.
我在做什么?
In order to use Proximity API, it has to be first enabled in Google Dev console. Using this tutorial I have enabled support for Proximity API for my project
According to this tutorial, I need to get client ID and secret. This is where I am confused. Credentials->Add credentials->OAuth2.0 client ID->select Chrome App radio button (since I am using Postman)->enter last part of Postman's Chrome Web store URL [which is fhbjgbiflinjbdggehcddcbncdddomop]->hit create button These steps will only generate a client ID, not a secret..am I doing something wrong?
From the Google Dev console, one can download an JSON file which has client id, auth URI and Token URI
我下载了这个,但如果我使用Postman,这没有什么帮助.我猜这个JSON文件可以包含在JS应用程序中.
并且,一旦我点击调试URL,我会看到以下屏幕
小智 62
邮递员将查询模仿Web应用程序的Google API
生成OAuth 2.0令牌:
创建OAuth 2.0客户端ID
getpostman.com
到授权域.单击保存.https://www.getpostman.com/oauth2/callback
Client ID
和Client secret
字段以供以后使用在Postman中选择"授权"选项卡,然后选择"OAuth 2.0"类型.点击"获取新访问令牌"
https://www.getpostman.com/oauth2/callback
https://accounts.google.com/o/oauth2/auth
https://accounts.google.com/o/oauth2/token
Client ID
在步骤2中生成(例如,'123456789012-abracadabra1234546789blablabla12.apps.googleusercontent.com')Client secret
在步骤2中生成(例如,'ABRACADABRAus1ZMGHvq9R-L')getpostman.com
)小智 42
我到目前为止找到的最好的方法是去Oauth游乐场:https://developers.google.com/oauthplayground/
在REST API请求的HTTP标头中,添加:"授权:承载".在这里,授权是关键,而"承载者".例如:"授权:bearer za29.KluqA3vRtZChWfJDabcdefghijklmnopqrstuvwxyz6nAZ0y6ElzDT3yH3MT5"
Zen*_*ahr 17
当前的答案已过时。这是最新的流程:
此处概述的方法仍然有效(10.12.2020),正如 alexwhan 所确认的那样。
我们将在示例中使用YouTube 数据 API。进行相应的更改。
确保您已为您的项目启用所需的 API。
https://console.cloud.google.com/apis/credentials
https://oauth.pstmn.io/v1/callback
Run Code Online (Sandbox Code Playgroud)
我们稍后将使用该文件来验证 Postman。
您可以在 .json 文件中找到您需要的所有其他内容。
忽略浏览器消息“不安全”等。这将显示,直到您的应用程序被谷歌官员筛选。在这种情况下,它将始终显示,因为 Postman 是应用程序。
小智 11
在Postman中将这些设置与oauth2一起使用:
访问令牌网址= https://accounts.google.com/o/oauth2/token
SCOPE = https://www.googleapis.com/auth/admin.directory.userschema
{
"fields": [
{
"fieldName": "role",
"fieldType": "STRING",
"multiValued": true,
"readAccessType": "ADMINS_AND_SELF"
}
],
"schemaName": "SAML"
}
Run Code Online (Sandbox Code Playgroud)
SCOPE = https://www.googleapis.com/auth/admin.directory.user
PATCH https://www.googleapis.com/admin/directory/v1/users/admin@email.com
{
"customSchemas": {
"SAML": {
"role": [
{
"value": "arn:aws:iam::123456789123:role/Admin,arn:aws:iam::123456789123:saml-provider/GoogleApps",
"customType": "Admin"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我发现我没有为正确的应用类型生成凭据.
如果您使用Postman测试Google oAuth 2 API,请选择
凭据 - >添加凭据 - > OAuth2.0客户端ID - > Web应用程序.
小智 5
这是一个老问题,但它没有选择答案,我只是自己解决了这个问题。这是我的解决方案:
确保您首先设置为使用您的 Google API。请参阅 Google 的先决条件列表。我在使用“Google 我的商家”,所以我也经历了它的入门流程。
在OAuth 2.0 playground 中,步骤 1 要求您选择要进行身份验证的 API。选择或输入适用于您的案例(在我的 Google 我的商家案例中,我必须将https://www.googleapis.com/auth/plus.business.manage输入到“输入您自己的范围”输入字段中)。注意:这与入门指南的“发出简单的 HTTP 请求”部分的第 6 步中描述的内容相同。
假设身份验证成功,您应该在 OAuth 操场的“步骤 1 的结果”步骤中得到一个“访问令牌”。将此令牌复制到剪贴板。
打开 Postman 并根据需要打开您想要的任何集合。
在 Postman 中,确保选择“GET”作为请求类型,然后单击请求类型下拉列表下方的“授权”选项卡。
在授权“TYPE”下拉菜单中,选择“Bearer Token”
将您之前从 OAuth 游乐场复制的“访问令牌”粘贴到 Postman 中显示的“令牌”字段中。
差不多好了!要测试是否有效,请将https://mybusiness.googleapis.com/v4/accounts/放入 Postman 的主 URL 输入栏中,然后单击发送按钮。您应该在响应中得到一个 JSON 帐户列表,如下所示:
{
"accounts": [
{
"name": "accounts/REDACTED",
"accountName": "REDACTED",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED"
}
},
{
"name": "accounts/REDACTED",
"accountName": "REDACTED",
"type": "LOCATION_GROUP",
"role": "OWNER",
"state": {
"status": "UNVERIFIED"
},
"permissionLevel": "OWNER_LEVEL"
}
]
}
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
117260 次 |
最近记录: |