Getting Google OAuth Access Token using Google APIs
OAuth access token for Google Drive
If you need to access your Google drive and read your contents through an API, you will need the Google OAuth access token associated with your google drive.
Here I have explained how to get that access token using Google APIs.
- Go to this link.
- Login to your Google account.
- Create a project using a project name and click on “CREATE” button.
4. Select the project you have created.
5. Click on “Open” button.
6. To enable Google Drive API, click on Google Drive API and then click on “ENABLE” button.
7. Click on “Create Credentials” button.
8. Choose “Web browser (Javascript)” for the “Where will you be calling the API from?” dropdown.
9. Select “ User data” for the “What data will you be accessing?”.
10. Click on “What credentials do I need?” button.
11. Provide a redirect URL for the “Authorized redirect URIs”.
Ex: https://www.maxsoftlk.com
12. Click on “Create OAuth client ID” button.
13. Provide a “product name”.
Ex: Test1
14. Click on “Continue” button.
15. Click on “Download” button to download this credential information in JSON format.
16. Click on “Done” button.
17. Change this URL according to the parameters given by you in the above steps.
Note: Your Client ID can be found from the file you have downloaded in step 15.
Ex: https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&response_type=code&access_type=offline&redirect_uri=https://www.maxsoftlk.com&client_id=1072307075112-fposi9hsdfghjkd3239f6gbfpkfasfpk.apps.googleusercontent.com
18. Copy the above URL and paste it in an incognito mode of your browser.
19. Select the Google account which you have logged in previously.
20. If you are come-up with this screen, click on Advanced link and then click on go with unsafe mode link.
21. Click on “Allow” button.
22. Copy the URL on the address bar.
23. Paste it in the note pad and copy the code.
Ex: https://www.maxsoftlk.com/?code=4/WwBf2eVqGtlxmWEGHGymGi18OJCj3JFMhXouWO1jrdnyWGqH4pcNoprdcFGwTWA_AG-sX3nRqEUn_Z2x0WGHhQg&scope=https://www.googleapis.com/auth/drive#
The code is: 4/WwBf2eVqGtlxmWEGHGymGi18OJCj3JFMhXouWO1jrdnyWGqH4pcNoprdcFGwTWA_AG-sX3nRqEUn_Z2x0WGHhQg
24. Now you can use these details to invoke the Google API and get the Google OAuth Access token for the Google Drive.
25. Open the Postman
26. Create a new request with these details.
HTTP Method: POST
Body Type: form-data
27. Click on “Send” button and get the access token.
Note: Postman Collection
Happy Programming !!!