[英]Golang - get list of files from a shared Google Drive folder
I am trying to list files and their IDs from a Google Drive folder using a known folder ID.我正在尝试使用已知文件夹 ID 列出 Google 云端硬盘文件夹中的文件及其 ID。
The drive service set up seems to be successful.驱动服务设置似乎是成功的。 But, I get a panic attempting to populate a variable with the info.但是,我在尝试用信息填充变量时感到恐慌。 Here is a snippet of the code:这是代码片段:
driveService, err := drive.NewService(ctx, option.WithCredentialsFile("../serverFiles/credentials.json"))
if err != nil {
log.Printf("Unable to retrieve Drive client: %v", err)
}
r, err := driveService.Files.List().
DriveId('XXXXXXXXXX').
PageSize(10).
Fields("nextPageToken, files(id, name)").
Do()
if err != nil {
log.Fatalf("Unable to retrieve files: %v", err)
}
Here is the error I get:这是我得到的错误:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x14312db]
Thanks for any help.谢谢你的帮助。
EDIT编辑
Thanks to @Tanaike's answer, I learned that I was confused about some points.感谢@Tanaike 的回答,我了解到我对某些要点感到困惑。 I am not attempting to get a list of files from a shared Drive, but a shared folder.我不是要从共享驱动器获取文件列表,而是要从共享文件夹获取文件列表。
I am using a service account to access.我正在使用服务帐户进行访问。 In another script the same service account is able to write to this same drive folder.在另一个脚本中,同一服务帐户能够写入同一驱动器文件夹。 So, I think permissions are OK.所以,我认为权限是可以的。
Here is how I am now trying to get the list (driveService is set up the same as above)这是我现在尝试获取列表的方式(driveService 的设置与上面相同)
r, err := driveService.Files.List().
Corpora("user").
PageSize(10).
Q("'XXXXXXXX' in parents").
Fields("nextPageToken, files(id, name)").
Do()
I still get the panic and signal.我仍然得到恐慌和信号。
I believe your goal is as follows.我相信你的目标如下。
In this case, how about the following modification?在这种情况下,如何进行以下修改?
r, err := driveService.Files.List().
DriveId('XXXXXXXXXX').
PageSize(10).
Fields("nextPageToken, files(id, name)").
Do()
r, err := driveService.Files.List().
DriveId("XXXXXXXXXX").
Corpora("drive").
SupportsAllDrives(true).
IncludeItemsFromAllDrives(true).
PageSize(10).
Fields("nextPageToken, files(id, name)").
Do()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.