

- Drive scope authorization how to#
- Drive scope authorization install#
- Drive scope authorization code#
Now, let’s add a function to our connect_to_google_drive.py that would retrieve all the files that we have in our Google Drive. (venv_google_api) MacBook-Pro:first_medium_project bobthedude$ ls credentials/ # output as below client_secret.json credentials.json Awesome job! We have now obtained our access token which we can use to connect to Google Drive API resources. successĪdditionally, you will see a new file credentials.json gets created in the credentials folder. credentials/credentials.json: No such file or directory warnings.warn(_MISSING_FILE_MESSAGE.format(filename)) Your browser has been opened to visit: If your browser is on a different machine then exit and re-run this application with the command-line parameter -noauth_local_webserver Authentication successful. Users/bobthedude/virtualenv/venv_google_api/lib/python3.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access. And if you go back to your terminal, you should see an additional 2 lines (indicating authentication success) printed as follows.

If successful, your browser will return a page with the following text The authentication flow has completed. Select the Google account on which you set up your API and credentials in the previous step. credentials/credentials.json: No such file or directory warnings.warn(_MISSING_FILE_MESSAGE.format(filename)) Your browser has been opened to visit: If your browser is on a different machine then exit and re-run this application with the command-line parameter -noauth_local_webserverĪ browser tab will open after the above command execution.

(venv_google_api) MacBook-Pro:~ bobthedude$ cd first_medium_project (venv_google_api) MacBook-Pro:first_medium_project bobthedude$ python connect_to_google_drive.py # below is the output of the above command /Users/bobthedude/virtualenv/venv_google_api/lib/python3.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access. For the first time only, you need to execute the script from your terminal. Note: if you execute the above script from an IDE (I use P圜harm), you would get an error. Follow below commands to get your access token. Now, save the file and go to your terminal. Your access token will be stored in credentials/credentials.json upon the browser authentication, which I will go through after this. from apiclient import discovery from httplib2 import Http from oauth2client import client, file, tools # define path variables credentials_file_path = './credentials/credentials.json' clientsecret_file_path = './credentials/client_secret.json' # define API scope SCOPE = '' # define store store = file.Storage(credentials_file_path) credentials = store.get() # get access token if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(clientsecret_file_path, SCOPE) credentials = n_flow(flow, store)
Drive scope authorization code#
Let’s write the code that needs to go into connect_to_google_drive.py. first_medium_project | |_credentials | | | |_client_secret.json | |_connect_to_google_drive.py The connect_to_google_drive.py is the Python file that contains instructions to connect to Google Drive API. Your project structure should look like this to begin with.
Drive scope authorization how to#
If you don’t know how to do this, follow this tutorial here.
Drive scope authorization install#
MacBook-Pro:~ bobthedude$ virtualenv venv_google_api MacBook-Pro:~ bobthedude$ source venv_google_api/bin/activate # install all the dependent packages (venv_google_api) MacBook-Pro:~ bobthedude$ pip install google-api-python-client oauth2clientĬreate a folder in the project directory called credentials to store your client_secret.json which you can download from your Google Console. We are going to start with installing google-api-python-client and oauth2client libraries. Before we begin, let’s set up a virtual environment to contain and install all the dependencies for this project.
