If you have not set up your Google Drive API, the scope and credentials please follow this tutorial here. Show In order to be able to access the API resources, we need to get the access token. Since the API resources that we want to access contain sensitive scope (accessing files in Google Drive), we need to do a browser authentication for the first time. Before we begin, let’s set up a MacBook-Pro:~ bobthedude$ virtualenv venv_google_api Create a folder in the project directory called Your project structure should look like this to begin with. The first_medium_project Let’s write the code that needs to go into from apiclient import discovery Your access token will be stored in Now, save the file and go to your (venv_google_api) MacBook-Pro:~ bobthedude$ cd first_medium_project A browser tab will open after the above command execution. Select the Google account on which you set up your API and credentials in the previous step. Then click on Allow. Once again, Google will prompt you and ask for a confirmation if you want to allow your First Medium Application to access your Google Drive files. Go on and click on Allow. If successful, your browser will return a page with the following text /Users/bobthedude/virtualenv/venv_google_api/lib/python3.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access ./credentials/credentials.json: No such file or directory Additionally, you will see a new file (venv_google_api) MacBook-Pro:first_medium_project bobthedude$ ls credentials/# output as below Now, let’s add a function to our from apiclient import discovery, errors Now, go to your (venv_google_api) MacBook-Pro:first_medium_project bobthedude$ python connect_to_google_drive.py# output will look like this You can see from the above, our Python script has successfully connected to the Google Drive API resources, retrieved all the files and printed the file metadata. There’s a lot of other things that you can do
with this. You can add a few lines of code that accepts a file name so that your Python script will retrieve the file metadata for a specific file that you are interested in. Let’s modify the # define a function to retrieve all files In the next part of this tutorial series, I am going to show you how we can download a specific worksheet from a Google sheet into a csv file. Also, we will transform the code above into a command line application, rather than just a plain Python script. You can see the first part of this tutorial here. Stay tuned for part III! 😃 How do I use Google Docs API in Python?A Google account.. Step 1: Install the Google client library. To install the Google client library for Python, run the following command: pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib. ... . Step 2: Configure the sample. To configure the sample: ... . Step 3: Run the sample. To run the sample:. How does Python read data from Google Drive?1) Install PyDrive. The first step is to install PyDrive. ... . 2) Authenticate. The second step is to authenticate and create a PyDrive client.. 3) Authorizing. ... . 4) Generating a shareable link. ... . 5) Getting the file_id. ... . 6) Load the CSV. ... . 7) Showing the Results.. Can I run Python on Google Drive?You can use the powerful and popular Python language in your Google Drive, and the set-up will take less than five minutes.
Is there an API for Google Drive?The Google Drive API allows you to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Drive, and create robust functionality in your application using the Drive API.
|