Using Google API for one own account without OAuth

In particular, I would like to use the Gmail API to access my own mail only . Is there a way to do this without OAuth and just an API key and / or client id and secret?

Using an API key like:

require('googleapis').gmail('v1').users.messages.list({ auth: '<KEY>', userId: '<EMAIL>') });

      

throws the following error:

{ errors: 
   [ { domain: 'global',
       reason: 'required',
       message: 'Login Required',
       locationType: 'header',
       location: 'Authorization' } ],
  code: 401,
  message: 'Login Required' }

      

I'm guessing this message means they want the correct OAuth Authorization header. I would do it, but I suppose it is not possible without submitting a web page.

+3


source to share


1 answer


Strict answer to the question "Is there a way to do this without OAuth and just an API key and / or client ID and secret?" not.

However, you can achieve what you are looking for using OAuth. You just need to store a refresh token, which you can use at any time to request an Auth token to access your gmail.



To get the refresh token, you can write a simple web application to do one-time authentication, or follow these steps here How do I authorize the application (website or installed) without user intervention? (canonical?) which allows you to do the entire authentication flow with the Oauth Playground.

+4


source







All Articles