Search code examples
restoauth-2.0service-accountsfitness

Service account authentication for Google Fit API


I am quite a beginner and I am trying to write a standalone Node/JS application that will run on a raspberry pi, without any GUI.

I need to retrieve physical activity data from the Google Fitness REST API without using oauth2. I understand it can be done using a service account (?). So I activated the Fitness API, created oauth2 credentials and a service account. Created a key, that I am sending in my requests.

It works in the Google Docs API as in the example below, but when using the same apprach in the Google Fit API, I get the dreaded "error 403, insufficient credentials for this scope".

const auth = new docs.auth.GoogleAuth({
  keyFilename: 'MY_PRIVATE_KEY_HERE.json',
    // Scopes can be specified either as an array or as a single, space-delimited string.
  scopes: ['https://www.googleapis.com/auth/documents']
});

Does the Fit API require oauth2 authentification, or can a service acount be used ?

Thanks for your help,

Lorenzo


Solution

  • On their webiste it says that you need to use OAuth 2.0

    "Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you."