How to access a gmail account I own using Gmail API?

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.


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:

  • Register your App at Google, and say what APIs you want your App to have access to (only the Gmail API in this case). This will give you two strings, a client_id and a client_secret (which is the content of the client_secrets.json -file above).
  • Since you are just going to write a script for your own account only, you don't need a http-server. The Oauth Playground will suffice. Press the Settings Cog on the top right and use your own OAuth credentials.
  • Select the Gmail API in the list of APIs and follow the outlined steps.
  • Now you have an access_token and a refresh_token you can use to keep your script going indefinitely!


    To fully understand the use of Gmail API, going through Gmail API Overview really will make a difference.

    And you can also use these documentations to start building a Gmail app:

  • The client libraries are available for download in several languages and simplify making API requests.
  • The developer guide topics help you better understand how to implement particular use cases.
  • The API reference gives you details on every resource and method in the Gmail API.
  • I hope these help.

    链接地址: http://www.djcxy.com/p/91948.html

    上一篇: 带Presenter的RxJava和用于配置更改的保留片段

    下一篇: 如何访问我使用Gmail API的gmail帐户?