我试着用golang客户端为google workspace目录创建Schema,使用以下代码:
config, err := google.ConfigFromJSON(b, admin.AdminDirectoryUserReadonlyScope, admin.AdminDirectoryUserScope,
admin.AdminDirectoryCustomerScope, admin.AdminDirectoryCustomerReadonlyScope)
if err != nil {
log.Fatalf("Unable to parse client secret file to config: %v", err)
}
srv, err := admin.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve directory Client %v", err)
}
schemaCall := srv.Schemas.Insert("C03uwpzz5", &admin.Schema{
Fields: []*admin.SchemaFieldSpec{
{
DisplayName: "Display Name",
FieldName: "EmployeeNumber",
FieldType: "STRING",
MultiValued: false,
},
},
})
_, errDo := schemaCall.Do()
if errDo != nil {
log.Fatalf("Unable to retrieve directory Client %v", errDo)
}
此代码参考包括以下主题:
- https://developers.google.com/admin-sdk/directory/v1/guides/manage-schemas#create_schema
- https://developers.google.com/admin-sdk/directory/v1/quickstart/go
但每次我收到这个错误
2023/02/16 00:38:11 Unable to retrieve directory Client googleapi: Error 403: Request had insufficient authentication scopes.
Details:
[
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"domain": "googleapis.com",
"metadata": {
"method": "ccc.hosted.frontend.directory.v1.DirectorySchemas.Insert",
"service": "admin.googleapis.com"
},
"reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT"
}
]
More details:
Reason: insufficientPermissions, Message: Insufficient Permission
我尝试了所有相关的范围,不幸的是,我找不到正确的。
1条答案
按热度按时间rjzwgtxy1#
我找到了正确的瞄准镜。是
https://www.googleapis.com/auth/admin.directory.userschema