设置Google用户的建筑物ID:位置属性抛出异常:“必需参数:[resource.location.field [0] .Value]” 我正在尝试使用.NET Google Admin SDK设置新用户的构建ID。我正在使用“位置”属性来做到这一点。 这是Google Admin Console中的构建ID: 在我的代码中: var newuser ...

问题描述 投票:0回答:1
属性来做到这一点。

在Google管理员控制台中的

Building id

在我的代码中:

var newUser = new User() { // ... }; // ... newUser.Locations = new List<UserLocation>() { new() { BuildingId = command.BuildingId, } }; // ... var request = _service.Users.Insert(newUser); var user = await request.ExecuteAsync(); A screenshot of the 最后一行投掷Google.GoogleApiException

服务管理员抛出了例外。 httpstatuscode是badrequest。必需参数:[resource.location.field [0] .value]

	

TL; DR:设置区域和类型为
desk

newUser.Locations = new List<UserLocation>() { new() { Area = "desk", BuildingId = command.BuildingId, Type = "desk", } };
c# google-admin-sdk
1个回答
0
投票
解释

这里有两个问题:

需要该位置的属性。

下面的变化消除了例外。但是,建筑物ID并未显示在GUI中。

Area

  1. 对于要在GUI中显示的构建ID,也必须设置newUser.Locations = new List<UserLocation>() { new() { Area = "desk", BuildingId = command.BuildingId, } };

    基于GUI集合TypeType

    在设置时,看起来两个属性都需要将两个属性设置为

    Area

    .
    在下面的更改中,建筑物ID现在在GUI中显示在
  2. 雇员Info中的GUI中:
  3. Building id

    
    
    
    方法论
    
    I通过在GUI中设置
    desk
    ,然后通过API使用户发现了这一点。 不幸的是,在.NET Google Admin SDK中,是类型的。在运行时,您可以看到它是一个纽顿(Newtonsoft)数组。我写了一个专门用于公共领域的扩展课:
    newUser.Locations = new List<UserLocation>()
    {
        new()
        {
            Area = "desk",
            BuildingId = command.BuildingId,
            Type = "desk",
        }
    };
    
        

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