Blog : Files: list
Files: list
Requires authorization
Lists the user's files. Try it now or see an example.
Requests with files.list accept the q parameter, which is a search query combining one or more search terms. For more information, see Search for files.
Note: This method returns all files by default. This includes files with trashed=true in the results. Use the trashed=false query parameter to filter these from the results.
Request
HTTP request
GET https://www.googleapis.com/drive/v2/files
Parameters
Parameter name Value Description
Optional query parameters
corpus string The body of items (files/documents) to which the query applies.
Acceptable values are:
"DEFAULT": The items that the user has accessed.
"DOMAIN": Items shared to the user's domain.
maxResults integer Maximum number of files to return. Acceptable values are 0 to 1000, inclusive. (Default: 100)
pageToken string Page token for files.
projection string This parameter is deprecated and has no function.
Acceptable values are:
"BASIC": Deprecated
"FULL": Deprecated
q string Query string for searching files. See Searching for files for more information about supported fields and operations.
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.metadata.readonly
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.apps.readonly
Request body
Do not supply a request body with this method.
Response
If successful, this method returns a response body with the following structure:
{
"kind": "drive#fileList",
"etag": etag,
"selfLink": string,
"nextPageToken": string,
"nextLink": string,
"items": [
files Resource
]
}
Property name Value Description Notes
kind string This is always drive#fileList.
etag etag The ETag of the list.
selfLink string A link back to this list.
nextPageToken string The page token for the next page of files.
nextLink string A link to the next page of files.
items[] list The actual list of files.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java.NETPHPPythonRubyJavaScriptGoObjective-C
Uses the Java client library.
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.Drive.Files;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
// ...
public class MyClass {
// ...
/**
* Retrieve a list of File resources.
*
* @param service Drive API service instance.
* @return List of File resources.
*/
private static List retrieveAllFiles(Drive service) throws IOException {
List result = new ArrayList();
Files.List request = service.files().list();
do {
try {
FileList files = request.execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
} catch (IOException e) {
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
} while (request.getPageToken() != null &&
request.getPageToken().length() > 0);
return result;
}
// ...
}