Search code examples
gmail-apigoogle-workspace

One-time use of the Gmail API - auth


I wrote a Python script that does some manipulations on my Gmail account. Now, I want to run it, and for that I need an OAuth token.

Do I have to go through the trouble of creating a project in Google Cloud, registering an application to use the Gmail APIs, authenticating myself and granting my script permissions to access my Gmail?

In GitHub, for example, I can create a Personal Access Token which is a scoped token I can directly use in such scripts.


Solution

  • Have a look at the quickstart

    When you run your code for the first time, you will be prompted to follow an URL to give authorization to the script. After this, the script will create an access token that is valid for one hour. A refresh token will also be automatically created. It will refresh your access token automatically when it expires and you will not need to do nothing anymore (unless you change the scopes).