Home > Blockchain >  Change "Shared drive settings" of Google Shared Drive
Change "Shared drive settings" of Google Shared Drive

Time:11-10

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/[email protected]/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)
// }

CodePudding user response:

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:"-"`

CodePudding user response:

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)
}
  • Related