I am trying to use the 'google-api-ruby-client' gem in a rails app to be able to request a user for access to their Google Drive. I am successfully navigating to the request permissions page where a user clicks accept. I have a callback function in a controller that captures the code that is returned upon a user clicking accept. I am then trying to fetch an access token. This is where I am getting hung up. I am getting this error:
My current controller code looks like this:
require 'google/api_client'
class GoogleDriveController < ApplicationController
def initialize
@client = Google::APIClient.new(:application_name => '????', :application_version => '1.0.0')
end
def auth
@client.authorization.client_id = ENV["GOOGLE_CLIENT_ID"]
@client.authorization.client_secret = ENV["GOOGLE_CLIENT_SECRET"]
@client.authorization.redirect_uri = ENV["GOOGLE_REDIRECT_URI"]
@client.authorization.scope = 'https://www.googleapis.com/auth/drive'
authorize_url = @client.authorization.authorization_uri
puts "https://#{authorize_url.host}#{authorize_url.path}?#{authorize_url.query}"
render json: {google_auth_url: "https://#{authorize_url.host}#{authorize_url.path}?#{authorize_url.query}"}
end
def callback
@client.authorization.code = params[:code] if params[:code]
access_token = @client.authorization.fetch_access_token!
@drive = @client.discovered_api('drive', 'v2')
end
end
Any help or nudges in the right direction would be greatly appreciated.
Thanks!
You can check below 3 links. They got the same error msg as you did.
Google OAuth2: Required parameter is missing: grant_type
Required Parameter is missing grant_type Google oauth2.0 AngularJS and Cordova inappbrowser
Google OAuth2 error - Required parameter is missing: grant_type on refresh