1

From article: https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md

Code:

credentials = ... same as above ...
credentials.code = authorization_code
credentials.fetch_access_token!

Then

If you want to restore a session afterwards, you can store credentials.refresh_token after credentials.fetch_access_token!

But after credentials.fetch_access_token! credentials.refresh_token is nil

How i can get refresh_token? Or save credentials to database for next time?

Filip Bartuzi
  • 5,711
  • 7
  • 54
  • 102
mpz
  • 1,906
  • 3
  • 15
  • 23
  • Can anyone add "google-auth-library-ruby" tag? In officall google rep - https://github.com/google/google-auth-library-ruby we have link for such tag in Support section (ask questions link). But it is not in SO actually – mpz Apr 09 '18 at 12:26

1 Answers1

1

Need add additional_parameters:

require "googleauth"

credentials = Google::Auth::UserRefreshCredentials.new(
  client_id: "YOUR CLIENT ID",
  client_secret: "YOUR CLIENT SECRET",
  scope: [
    "https://www.googleapis.com/auth/drive",
    "https://spreadsheets.google.com/feeds/",
  ],
  redirect_uri: "http://example.com/redirect",
  :additional_parameters => {
         "access_type"=>"offline",
         "include_granted_scopes"=>"true",
         "prompt" => "consent"
  }
)
auth_url = credentials.authorization_uri

credentials.code = authorization_code
credentials.fetch_access_token!

then get:

refresh_token = credentials.refresh_token 

and then refresh_token can be stored in database and used later:

credentials.refresh_token = refresh_token
credentials.fetch_access_token!
session = GoogleDrive::Session.from_credentials(credentials)
mpz
  • 1,906
  • 3
  • 15
  • 23
  • do you have a repo ?, im getting troubles to get a session onli for get the list of files updated everytime when an app starts – qleoz12 Jun 14 '23 at 15:33