英文:
Change "Shared drive settings" of Google Shared Drive
问题
我想使用Golang的Google Drive API来更改Google共享驱动器的“共享驱动器设置”。
当我创建共享驱动器时,我将“DomainUsersOnly”和“DriveMembersOnly”设置为false,但它没有起作用。
我参考了下面的链接。
链接:https://pkg.go.dev/google.golang.org/api@v0.52.0/drive/v3#DriveRestrictions
// restrict := &drive.DriveRestrictions{
// AdminManagedRestrictions: false,
// DomainUsersOnly: false,
// DriveMembersOnly: false,
// }
// exFolder := &drive.Drive{
// Name: "試験_ZZ_TEST",
// Restrictions: restrict,
// }
// res, err := drive.NewDrivesService(srv).Create(reqId, exFolder).Do()
// if err != nil {
// log.Fatalf("无法创建共享驱动器:%v /n", err)
// }
英文:
I want to change "Shared drive settings" of Google Shared Drive by Google Drive API with Golang.
I set false to "DomainUsersOnly" and ”DriveMembersOnly" of "Shared drive settings" when I created shared drive.
But it was not working.
I referred to the link below.
link:https://pkg.go.dev/google.golang.org/api@v0.52.0/drive/v3#DriveRestrictions
// restrict := &drive.DriveRestrictions{
// AdminManagedRestrictions: false,
// DomainUsersOnly: false,
// DriveMembersOnly: false,
// }
// exFolder := &drive.Drive{
// Name: "試験_ZZ_TEST",
// Restrictions: restrict,
// }
// res, err := drive.NewDrivesService(srv).Create(reqId, exFolder).Do()
// if err != nil {
// log.Fatalf("Can not create shared drive: %v /n", err)
// }
答案1
得分: 1
你需要在ForceSendFields
中指定这些布尔字段。
restrict := &drive.DriveRestrictions{
AdminManagedRestrictions: false,
DomainUsersOnly: false,
DriveMembersOnly: false,
ForceSendFields: []string{"AdminManagedRestrictions", "DomainUsersOnly", "DriveMembersOnly"},
NullFields: []string{"AdminManagedRestrictions", "DomainUsersOnly", "DriveMembersOnly"},
}
ForceSendFields
的文档如下:
// ForceSendFields是一个字段名称列表(例如“AdminManagedRestrictions”),用于无条件地包含在API请求中。默认情况下,具有空值或默认值的字段将从API请求中省略。但是,任何出现在ForceSendFields中的非指针、非接口字段都将被发送到服务器,无论该字段是否为空。这可用于在Patch请求中包含空字段。
ForceSendFields []string `json:"-"`
英文:
You need to specify these boolean fields in ForceSendFields
.
restrict := &drive.DriveRestrictions{
AdminManagedRestrictions: false,
DomainUsersOnly: false,
DriveMembersOnly: false,
ForceSendFields: []string{"AdminManagedRestrictions", "DomainUsersOnly", "DriveMembersOnly"},
NullFields: []string{"AdminManagedRestrictions", "DomainUsersOnly", "DriveMembersOnly"},
}
document of ForceSendFields
// ForceSendFields is a list of field names (e.g.
// "AdminManagedRestrictions") to unconditionally include in API
// requests. By default, fields with empty or default values are omitted
// from API requests. However, any non-pointer, non-interface field
// appearing in ForceSendFields will be sent to the server regardless of
// whether the field is empty or not. This may be used to include empty
// fields in Patch requests.
ForceSendFields []string `json:"-"`
答案2
得分: 0
创建时它没有工作,
但是在更新后它工作了。
true参数的复选框被关闭。
restrict := &drive.DriveRestrictions{
DomainUsersOnly: true,
DriveMembersOnly: true,
}
newmetadate.Restrictions = restrict
res, err := srv.Drives.Update(did, newmetadate).UseDomainAdminAccess(true).Do()
if err != nil {
log.Fatalf("error update shared drive: %v /n", err)
}
英文:
it was not working when created,
but it was working then update.
parameter of true was checkbox off.
restrict := &drive.DriveRestrictions{
DomainUsersOnly: true,
DriveMembersOnly: true,
}
newmetadate.Restrictions = restrict
res, err := srv.Drives.Update(did, newmetadate).UseDomainAdminAccess(true).Do()
if err != nil {
log.Fatalf("error update shared drive: %v /n", err)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论