
Google Drive Credentials.json for API Clients is a crucial file that allows your application to access Google Drive's API. This file is used to authenticate your application and authorize access to user data.
To create a Credentials.json file, you'll need to register your application in the Google Cloud Console, which generates a Client ID and Client Secret. You can then use these credentials to create a Credentials.json file.
The Credentials.json file contains sensitive information, including your Client ID and Client Secret. This file should be stored securely, as it provides access to your user's data.
In the Credentials.json file, the client_secret field stores your Client Secret, which is used to authenticate your application with Google Drive's API.
Explore further: Google Cloud Platform Data
Setting Up Google Drive API
To set up the Google Drive API, you need to create a new Google account for API access. Create a new Google account for Google drive and enable that account for API access through the Google Cloud console.
Suggestion: Google Drive Api Key
You'll also need to create an OAuth client ID and select Web Application. Add the authorize URLs and create the client.
To obtain the credentials.json file, download the client you just created. This file contains your Client ID and Client Secret, which you'll need later.
You can see that the script is supposed to retrieve the token.json file when you give it the credentials.json file, but this may not work if you're running the script in a non-CLI environment.
To get the Access Token, you'll need to post the authorize URL into a browser that's logged into the Google account where your API is registered. Go through the prompts to allow access, and after this is done, it will take you back to your redirect_uri and give you an Authorization code.
Here's a breakdown of the authorize URL:
- client_id: Your Client ID from the credentials.json file
- redirect_uri: The URL that you set up when creating the OAuth client ID
- scope: The scope of access you're requesting (in this case, drive.metadata.readonly)
- response_type: The type of response you're expecting (in this case, code)
- access_type: Whether you want offline access (in this case, offline)
- prompt: Whether you want to prompt the user for consent (in this case, consent)
The resulting URL should look something like this: https://accounts.google.com/o/oauth2/auth?client_id=XXXXXXXXXXX&redirect_uri=XXXXXXXXX&scope=https://www.googleapis.com/auth/drive.metadata.readonly&response_type=code&access_type=offline&prompt=consent
You can see the format of the resulting authorization code: https://redirect_uri/?code=[Authorisaton Code]&scope=[SCOPE]
To exchange the authorization code for an access token, you'll need a Linux machine with Curl. You can install Linux on Windows using WSL.
Take a look at this: Https Drive Google Com Drive Quota
Authorizing Google Drive Access
To authorize Google Drive access, you'll need to create a new project in the Google Cloud Console API. This will allow you to enable the Google Drive API and create credentials for your application.
First, go to the Google Cloud Console API and create a new project. You can do this by clicking on the "Select a project" dropdown menu and then clicking on the "New Project" button.
Next, enable the Google Drive API by clicking on the "Enable APIs and Services" button and searching for "Google Drive API". Click on the result to enable it.
Now, create an OAuth client ID by clicking on the "Create Credentials" button and selecting "OAuth client ID". Choose "Desktop app" as the application type and enter a name for the credential.
You'll receive a Client ID and Client secret, which you'll need to save in a JSON file named "credentials.json". This file will be used to authenticate your application with Google Drive.
Readers also liked: How to Set up a Shared Google Drive
If the content of the "redirect_uris" field in the JSON file is pointing to localhost, you'll need to change it to "urn:ietf:wg:oauth:2.0:oob".
To do this, open the JSON file and locate the "redirect_uris" field. You can do this by searching for the field or by manually navigating to it.
Once you've made the necessary changes, save the JSON file and move it to your working directory.
Here's a step-by-step summary of the process:
- Create a new project in the Google Cloud Console API
- Enable the Google Drive API
- Create an OAuth client ID
- Save the Client ID and Client secret in a JSON file named "credentials.json"
- Change the "redirect_uris" field to "urn:ietf:wg:oauth:2.0:oob" if necessary
- Save and move the JSON file to your working directory
Sources
- https://medium.com/@cesantin/connecting-to-google-drive-using-golang-9953f4eb3340
- https://pariswells.com/blog/research/google-drive-api-credential-json-and-token-json-access-token
- https://developers.google.com/drive/api/quickstart/go
- https://stackoverflow.com/questions/58460476/where-to-find-credentials-json-for-google-api-client
- https://support.google.com/cloud/answer/6158849
Featured Images: pexels.com