Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant seem to get auto google sheets upload to work #167

Closed
jooj123 opened this issue Mar 29, 2018 · 4 comments
Closed

Cant seem to get auto google sheets upload to work #167

jooj123 opened this issue Mar 29, 2018 · 4 comments

Comments

@jooj123
Copy link
Contributor

jooj123 commented Mar 29, 2018

Pretty sure this is a bug

In the google sheets setup here:
https://github.com/paulirish/pwmetrics#defining-submit

It says "Take a client_secret and put it into the config as value of clientSecret property." - not sure what this means exactly.
I have downloaded the JSON file from google sheets api setup - thats in the format:

{
  "type": "service_account",
  "project_id": "blah",
  "private_key_id": "blah",
  "private_key": "keyblah",
  "client_email": "blah",
  "client_id": "blah",
  "auth_uri": "blah",
  "token_uri": "blah",
  "auth_provider_x509_cert_url": "blah",
  "client_x509_cert_url": "blah"
}

Does it mean just grabbing this object and putting it into pwmetrics-config.js clientSecret property ?

I have tried this with example config here:

...
  sheets: {
    type: 'GOOGLE_SHEETS', 
    options: {
      spreadsheetId: 'myspreadheetid',
      tableName: 'data',
    },
  },
  clientSecret: {
    // the object above
  },

But this doesnt work - I get error:

TypeError: Cannot read property 'client_secret' of undefined
    at GoogleOauth.<anonymous> (/Users/martin.jujou/Documents/projects/fe-server-search-results/node_modules/pwmetrics/lib/oauth/google-oauth.js:51:56)

Seems that the code here:

const clientSecret = credentials.installed.client_secret;

Seems incorrect as it checks for an "installed" property ?
I can fix this up but not sure if this property is there for a reason?

Also seems you need to configure a redirect uri in order for oauth.
Is there any way to setup with a service account so that this manual step is not required?
I would like for this sheets api integration to be part of CI - I can see there is an example to integrate puppeteer to do the login but this seems a bit clunky: googleapis/google-auth-library-nodejs#265

@denar90
Copy link
Collaborator

denar90 commented Apr 4, 2018

Hi. Looks like you generated wrong client secret.
Format of secret key has to be like this https://github.com/paulirish/pwmetrics/blob/v3.2.0/types/types.ts#L90

Does it mean just grabbing this object and putting it into pwmetrics-config.js clientSecret property ?

Yes it is)

Here's format of mine

clientSecret:
{
   "installed": {
      "client_id": "id",
      "project_id": "pwmetrcis",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://accounts.google.com/o/oauth2/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_secret": "key",
      "redirect_uris": [
         "url",
         "http://localhost"
      ]
   }
}

@jooj123
Copy link
Contributor Author

jooj123 commented Apr 4, 2018

@denar90 this format works

Seems its not clear from the docs so thats where the confusion lies - Ill throw up a PR

@denar90
Copy link
Collaborator

denar90 commented Apr 4, 2018

Cool 👍 I'd like to merge your PR ;)

@jooj123
Copy link
Contributor Author

jooj123 commented Apr 4, 2018

#169

@denar90 denar90 closed this as completed Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants