获取google OAuth中的自定义用户字段

问题描述 投票:0回答:1

我是API的新手,我想从与OAuth2的连接中获得自定义字段ScreenConnect。我在console.developers.google.com中创建了我的项目,并且已经授权了Admin SDK。在我的范围内,我输入https://www.googleapis.com/auth/admin.directory.user.readonly

但是我无法找回变量。如果我尝试https://www.googleapis.com/admin/directory/v1/customer/my_customer/schemas检索所有自定义架构(https://developers.google.com/admin-sdk/directory/v1/guides/manage-schemas)。我有the Insufficient Permission: Request had insufficient authentication scopes。但是https://www.googleapis.com/admin/directory/v1/users/userKey工作正常(https://developers.google.com/admin-sdk/directory/v1/reference/users/get)。因此,限制并非来自SDK。我认为这是一个网址错误,但我不明白发生了什么。

我解决了错误,权限不足,范围为https://www.googleapis.com/auth/admin.directory.userschema,但我仍然找不到如何获取变量的值

google-oauth2 google-admin-sdk
1个回答
0
投票

您使用的范围不是正确的范围,因为它仅授予readonly访问权限。为了访问您想要的目标,您应该使用以下方法:

  • https://www.googleapis.com/auth/admin.directory.user;

此外,如果要检索为用户的每个自定义架构设置的值,则必须发出以下GET请求,其中userKey是用户的电子邮件地址。

https://www.googleapis.com/admin/directory/v1/users/userKey

此外,还必须将customFieldMask参数设置为模式名称],将projection参数设置为自定义

因此,对于特定用户,您的请求将如下所示:

GET https://www.googleapis.com/admin/directory/v1/users/THE_EMAIL_OF_THE_USER?customFieldMask=NAME_OF_THE_SCHEMA&projection=custom&key=[YOUR_API_KEY] 

HTTP/1.1

Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json

参考

© www.soinside.com 2019 - 2024. All rights reserved.