I'm doing some analysis for a company I work for and I require using the Google Gmail API to see emails that have been sent to me.
My project is using Deno and as its a very new framework, Google doesn't have a third-party module to use with it. On the Google API documentation, all the quickstarts require using Google's libraries to authenticate and make requests.
I was wondering if there was a way to make Google API requests with simple fetch
requests so I can just develop my own little module for making Google API requests. I couldn't find any information on the Google API website about what specific REST requests are made to authenticate with their API.
If this isn't possible, please let me know so I can think about converting all my code to Node.js (I really don't want to do this).
CodePudding user response:
Google's SDK aren't doing anything magical. They're just fancy wrappers around a REST client.
You can look into the SDK source code to see exactly what they are doing. For example, here are the parameters you need for one of the calls: https://github.com/googleapis/google-api-nodejs-client/blob/2e3dbab2fe0a4fbc56f4a7135fcb873b34c78fe9/src/apis/gmail/v1.ts#L4490
You can see the exact specifics in the docs: https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list
CodePudding user response:
See Gmail API Overview Guide for the guidance. You will be implementing your own OAUTH2 solution rather than using their premade client libraries. For details on how to do that, see Using OAuth 2.0 for Web Server Applications
OAuth 2.0 allows users to share specific data with an application while keeping their usernames, passwords, and other information private. For example, an application can use OAuth 2.0 to obtain permission from users to store files in their Google Drives.
Basically, you users will be prompted to allow your app access to their Google account with scope that includes Gmail data. You'll get handed a token that is used to make the REST calls.