0
我试图在rails应用中使用'google-api-ruby-client'gem来请求用户访问其Google云端硬盘。我成功导航到用户点击接受的请求权限页面。我在控制器中有一个回调函数,用于捕获用户单击接受时返回的代码。我然后试图获取访问令牌。这是我被挂断的地方。我收到此错误:Google Oauth授权失败
我的电流控制器的代码如下所示:
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
任何帮助或在正确的方向轻推将不胜感激。
谢谢!
的问题是,他的使用由谷歌建立了一个API来获取访问令牌,而不是手动POST操作通过HTTP像其他回应 – Ramfjord