通过API访问用户GMail帐户

I am writing this goroutine that'll call the GMail API and poll my inbox every 2 minutes or so. The problem I am having trouble with is the authentication part because it'll need me to login and authenticate myself and give authorization to the app to read my inbox. I am trying to eliminate the part where I will need to login via the Web UI and give access to my program. Does anyone have any ideas on how to login and authenticate myself programmatically?

You should be able to use the steps here in order to generate and OAuth client ID, then use that to connect using oauth?:

https://github.com/google/GTMAppAuth/blob/master/Example-macOS/README.md

Failing that, you could use IMAP access to bypass the api entirely. Turn on imap in settings and use a library like this to access your messages:

https://github.com/emersion/go-imap/blob/v1/README.md