How to Create Google Drive API using Google Auth API
Google Drive is a popular and user-friendly free cloud-based storage service that allows us to save and access files online.
We can use Google Drive to store our files securely — to use Google drive for saving files and projects requires Google Drive API.
This step-by-step tutorial will teach you how to set up Google API authentication to save backup in Google Drive folder using Google Drive storage service.
In this guide, we will conjugate all the process that helps you get Google Client Secret, Client Id, Refresh Token and Folder Id for taking backup in Google Drive storage.
The Google Drive service works on a sync mechanism; It automatically syncs stored documents, photos and other important files.
How to Create Google Client ID, Secret Key, Refresh Token and Google Drive API
Google Drive API provides seamless access to manage resources; there are many crucial steps involved in getting the google auth API and google drive API.
1. In order to create the Google account credentials, you require to visit the Google Developers Console.
2. On the top right part of the Select a project screen you see a New Project button with icon. Click on the button to create a new project.
3. There is a side bar menu on your left, ensure that you click oin OAuth consent screen, further select the External radio button and click on Create button.
4. Add your Application name, User Support email, App domain, Developer contact information, next click on the Save and Continue button.
5. Click on Credentials, then click on the CREATE CREDENTIALS button; after the dropdown opens, click on the OAuth client ID.
6. In the next step, you see Create OAuth the client ID page visible; make sure to add the Application type and App Name.
7. You must add the site path in the Authorized redirect URIs.
You have to enter the Authorised redirect URIs (https://developers.google.com/oauthplayground), make sure to have a production URL, or you can also have a separate production credential.
8. You have to keep the OAuth client and secret key in the notepad because we will need it sooner.
9. Furthermore, click on the www.developers.google.com/oauthplayground/ link. As soon as you open the URL, you see a settings icon on the top right.
You need to click on it, and a drop-down will open; you have to look for “Use your own OAuth credentials” and select the checkbox option.
If you have added the https://developers.google.com/oauthplayground as a valid redirect URI in your Google APIs Console’s project.
Ensure that you add the client ID and secret assigned to a web application on your project below:
10. You must be seeing Select & authorize APIs on your left. You have to select the “Drive API v3” and click it.
After it expands, you can check every scope implied within the span of the API range and click the “Authorize APIs” button..
11. Next, the OAuth 2.0 playground screen opens; check the checkbox with the “Auto-refresh the token before it expires menu”. Then click on the “Exchange authorization code for tokens”.
12. Click on the “Library” menu item and look for “Google Drive API” under Google Workspace category and don’t forget to enable this service.
13. In the last step we will retrieve the Folder Id of Google drive, you can extract the URL from your Google Drive account.
Head over to your Google Drive account, and create a new Folder. After you create the folder in your Google Drive account, click on it. It will have the folder id implied in the URL.
Conclusion
In this comprehensive guide, we have learned how to create a Google API client, how to create and get the Google account refresh token, and most importantly, how to get the folder id to get the Google Drive API.