gimite / google-drive-ruby

A Ruby library to read/write files/spreadsheets in Google Drive/Docs.
Other
1.76k stars 495 forks source link

Signet::AuthorizationError error while using google-drive gem #363

Open wowremywang opened 4 years ago

wowremywang commented 4 years ago

I am using google_drive gem.

This is config.json.

{
  "client_id": "*****.apps.googleusercontent.com",
  "client_secret": "*****",
  "scope": [
    "https://www.googleapis.com/auth/drive",
    "https://spreadsheets.google.com/feeds/"
  ],
  "refresh_token": "*****"
}

Code: Add row to google sheet.

session = GoogleDrive::Session.from_config("#{Rails.root.join('config/config.json')}")
ws = session.spreadsheet_by_key(ENV["GOOGLE_SHEET_KEY"]).worksheets[0]
num_rows = ws.num_rows

worksheet_row.each_with_index do |column, index|
  ws[num_rows + 1, index + 1] = column
end

It was working but recently I am getting this error.

Signet::AuthorizationError (Authorization failed.  Server message:
{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}):

Any idea?

benjaminjackson commented 4 years ago

+1 on this, also impacted—looks like this may be addressed in commit 5af9a84baaa607139075fbf30225e5e357ac54a6

hadees commented 4 years ago

I'm having a similar issue but I'm using a service account. I have noticed that session.spreadsheet_by_key('<foobar>') does return an object from google. It seems to be just when accessing the worksheets which uses the sheets api. I know the default scope doesn't have sheets in it but adding it as a scope didn't help.

Bilal-Abbas commented 4 years ago

Any solution you have got ? I am facing the same problem

snex commented 4 years ago

I am experiencing this as well. I followed the instructions to create my credentials back in Feb when this issue first surfaced, and that solved it at the time. However I am now coming back to the project after a few months dormant and I am receiving the error. I validated my credentials in the Google developer console and they are correct. I am using the command line auth on behalf of myself.

hmt commented 3 years ago

Fix it this way:

{
  "client_id": "*****.apps.googleusercontent.com",
  "client_secret": "*****"
}

Just leave the two lines with your id and secret then you have to validate again if you have new credentials and it should work.