2

我正在尝试使用 golang通过https://cloud.google.com/identity/docs/reference/rest/v1/devices/list获取公司拥有的设备。我尝试过使用服务帐户并进行域范围的委派,甚至添加范围。似乎下面的代码总是给出空值(没有设备列表)。

我使用的示例 golang 代码:

cloudidentityService, err := cloudidentity.NewService(context.Background(), option.WithCredentialsFile("test.json"),
    option.WithScopes("https://www.googleapis.com/auth/cloud-identity.devices.lookup",
        "https://www.googleapis.com/auth/cloud-identity.groups","https://www.googleapis.com/auth/cloud-identity.groups.readonly",
        "https://www.googleapis.com/auth/cloud-platform"))

addevices, err := cloudidentityService.Devices.List().Do()

if len(addevices.Devices) == 0 {
    fmt.Println("empty")
} else {
    for _, u := range addevices.Devices {
        fmt.Println(u.Name)
    }
    return
    

请给个建议。我使用的参考代码是https://github.com/googleapis/google-api-go-client/blob/master/cloudidentity/v1beta1/cloudidentity-gen.go 如果有人可以通过邮递员提供建议,那也很棒。

4

0 回答 0