I want to run a node script as a cronjob which uses Gmail's API to poll a gmail account I own.
I am following these quickstart instructions:
I'm stuck on the first step. When requesting credentials for a cron script it tells me that "User data cannot be accessed from a platform without a UI because it requires user interaction for sign-in":
The docs are confusing in general, and mention "service accounts," "OAuth," and other things -- I cannot tell which apply to my use-case and which don't. I've used many SaaS APIs, and the typical workflow is to login to your account, get an API key and secret, and use those in your script to access the API. It seems this is not the paradigm used by the Gmail API, so I'd appreciate any guidance or links to clearer instructions.
Any web browser—Go to mail.google.com. and choose Gmail.
The Gmail API is a RESTful API that can be used to access Gmail mailboxes and send mail. For most web applications the Gmail API is the best choice for authorized access to a user's Gmail data and is suitable for various applications, such as: Read-only mail extraction, indexing, and backup.
Enable the GMail APIFrom the project, click on ENABLE APIS AND SERVICES and search for the Gmail API. Click on ENABLE. You now have the Gmail API enabled for your project. All you need now is to create some credentials for using the API.
I also find that the documentation can be confusing at times, but what you want to to is actually pretty straight forward once you get it:
client_id
and a client_secret
(which is the content of the client_secrets.json
-file above).Now you have an access_token
and a refresh_token
you can use to keep your script going indefinitely!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With