bestlaha.blogg.se

Google drive api service account
Google drive api service account









Scopes: A list auth scopes to authorize for the application.

google drive api service account google drive api service account

"""Get a service that communicates to a Google API.Īpi_name: The name of the api to connect to.Īpi_version: The api version to connect to. We can define a generic function to create a Google API service authenticated with credentials from a service account: def get_service(api_name, api_version, scopes, key_file_location): These are the required imports: from import Credentialsįrom googleapiclient.discovery import buildįrom googleapiclient.errors import HttpErrorįrom google.oauth2 import service_account Install the required dependencies as below: pip install -upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlibĭepending on your operating system, installing the dependencies may be different, for example, in archlinux, many popular packages can be installed system-wide with pacman: pacman -S python-google-api-python-client python-google-auth-oauthlib ImplementationĬreate a python file in a working directory, for example, googledrive.py, and copy the downloaded json key to this directory as well. Now select the recently created account by clicking on the email, go to the Keys tab, click Add key > Create new key, select JSON and click Create, make sure to store the file securely as this is the only copy of the key. The next step is to create the service account, click Menu ☰ > IAM & Admin > Service Accounts, click Create service account, enter the service account name and ID, click Create and continue, optionally select roles, we can leave it blank, click Continue and Done. Once the project is created, we need to enable the APIs that we want to access, in this case, Google Drive API, click Menu ☰ > APIs & Services> Library, search for Google Drive API, and select it, in the next screen, click enable. To create a service account, first, you need to create a project in the google cloud platform to associate the account with, go to the google cloud console, if it is the first time you are accessing it, you will need to accept the Terms of Service, once there, at the top-left, click Menu ☰ > IAM & Admin > Create a Project, enter a project name, optionally edit the project ID and click create. If you need to access your files from a program in Google Drive without needing you to authenticate yourself, that is, a machine-to-machine communication, then you will need to set up a service account.











Google drive api service account