Showing posts with label Google Drive. Show all posts
Showing posts with label Google Drive. Show all posts

2016/10/31

Google Drive API - How to find file id by filename and download non Google Doc files to local storage using Python

This tutorial is based on Google Drive API v3 and Python 2.7.9.

The code below allows its user to specify the name of the file to be searched for on his/her own Google Drive. Once the file is found, the user will then be prompted on whether to download the file to the local storage or not. The download is limited to non Google Doc files. For Google Doc files, please refer to the sample code at http://wei48221.blogspot.tw/2016/10/google-drive-api-uploading-downloading.html.

2016/10/26

PyDrive Quick Overview - Authentication and File Listing - PyDrive vs Drive API Python

I came across PyDrive (https://pythonhosted.org/PyDrive/index.html) while trying to learn how to use Python to access Google Drive via Google Drive API. For someone struggling to understand how to use the Google Drive API, I think it's a godsend to have PyDrive..

OAuth2 authentication

Using PyDrive

1
2
3
4
from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.

Google Drive APIs Explorer - Listing Files

This post is about how to use query for filtering the file results and selector to specify which fields to include in a partial response.

Listing files in the root folder

Assuming I want to list all the files that are not trashed in the root folder and I want to see the filename, id, and mimeType in the output result. Here is how to for the query in Google Drive APIs Explorer.

Step 1 - Go to https://developers.google.com/drive/v3/reference/files/list.

Step 2 - Select user for the corpus field, enter 'root' in parents and trashed=false for the field for q, and enter files(name,id,mimeType) for the field for fields.