I have stuck with function that must to return me a list of all files from directory (in this case directory is "root"). When I call this function, it return me files that only I added with my program (this program also can upload files to Google Drive), not all files. And it also shows me files that I deleted :/. What I do wrong? This function I was copied from Google Drive API Quickstart
service, err := getService()
if err != nil {
log.Fatalf("Unable to retrieve Drive client: %v", err)
}
r, err := service.Files.List().Q("'root' in parents").Do()
if err != nil {
log.Fatalf("Unable to retrieve files: %v", err)
}
fmt.Println("Files:")
if len(r.Files) == 0 {
fmt.Println("No files found.")
} else {
for _, i := range r.Files {
fmt.Printf("%v (%vs )\n", i.Name, i.Id)
}
}
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
From the situation of When I call this function, it return me files that only I added with my program (this program also can upload files to Google Drive), not all files.
, I thought that your scopes might include https://www.googleapis.com/auth/drive.file
. When https://www.googleapis.com/auth/drive.file
is used as the scope, only the files created by the application are retrieved.
In order to retrieve all files just under the root folder, please use the following scopes.
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.metadata.readonly
https://www.googleapis.com/auth/drive.metadata
.If you want to retrieve only the file list, the scopes of .readonly
can be used.
From your question, I could notice that you are using google-api-go-client with golang and Go Quickstart. In this case, how about the following modification?
If drive.DriveFileScope
is included in the scopes, please modify as follows.
config, err := google.ConfigFromJSON(b, drive.DriveFileScope)
To:
config, err := google.ConfigFromJSON(b, drive.DriveMetadataScope)
or
config, err := google.ConfigFromJSON(b, drive.DriveReadonlyScope)
drive.DriveScope
.token.json
of tokFile := "token.json"
. And please run the script and authorize again. By this, the modified scopes are reflected to the access token and refresh token. Please be careful this.If I misunderstood your question and this was not the direction you want, I apologize.