google-drive-ruby icon indicating copy to clipboard operation
google-drive-ruby copied to clipboard

Signet::AuthorizationError error while using google-drive gem

Open wowremywang opened this issue 6 years ago • 5 comments

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?

wowremywang avatar Feb 05 '20 20:02 wowremywang

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

benjaminjackson avatar Feb 10 '20 23:02 benjaminjackson

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.

hadees avatar Feb 20 '20 07:02 hadees

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

Bilal-Abbas avatar Jun 18 '20 13:06 Bilal-Abbas

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.

snex avatar Oct 03 '20 09:10 snex

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.

hmt avatar Apr 12 '21 06:04 hmt