Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Last active June 18, 2018 12:03
Show Gist options
  • Save amitpatelx/b11ce603f53d4c49f49ee7dd31a4739d to your computer and use it in GitHub Desktop.
Save amitpatelx/b11ce603f53d4c49f49ee7dd31a4739d to your computer and use it in GitHub Desktop.
Generate Google API token using refresh token
require "googleauth"
redentials =
Google::Auth::UserRefreshCredentials.new(
client_id: "3453463453ghjejfrekjfrekgjher.apps.googleusercontent.com",
client_secret: "dnbddfjfjkffrfrfj",
scope: ["https://www.googleapis.com/auth/drive"], # enter the scope for a service whichever you want to use
additional_parameters: { "access_type" => "offline" }) # DO not forgot to add this
# Set the refresh token
credentials.refresh_token = '1/clpHfRpyVonjRpYFyfstY3zD9TSX6MgcX2C1lJ-RTEQ'
# Generate new access token
credentials.fetch_access_token!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment