无法在Ruby on Rails上加载Google API客户端

时间:2022-01-29 15:24:14

I want to verify user profile from Google Authorization code sent by android client, to do that, we have to download client_secrets.json and put it inside our rails app. Just like this tutorial https://developers.google.com/identity/protocols/OAuth2WebServer

我想验证Android客户端发送的Google授权代码的用户配置文件,为此,我们必须下载client_secrets.json并将其放入我们的rails应用程序中。就像本教程https://developers.google.com/identity/protocols/OAuth2WebServer一样

But when I try to follow this step

但是当我尝试按照这一步时

require 'google/apis/drive_v2'
require 'google/api_client/client_secrets'

client_secrets = Google::APIClient::ClientSecrets.load
auth_client = client_secrets.to_authorization
auth_client.update!(
  :scope => 'https://www.googleapis.com/auth/drive.metadata.readonly',
  :redirect_uri => 'http://www.example.com/oauth2callback',
  :additional_parameters => {
    "access_type" => "offline",         # offline access
    "include_granted_scopes" => "true"  # incremental auth
  }
)

Rails throws an error said "No client_secrets.json filename supplied and/or could not be found in search path." The errors shows up even though I have insert client_secrets.json inside config/client_secrets.json

Rails抛出一个错误,说“没有提供client_secrets.json文件名和/或在搜索路径中找不到。”即使我在config / client_secrets.json中插入client_secrets.json,错误也会显示出来

Do you know what's the problem or what's the alternative for this solution, thank you.

你知道这个问题是什么问题或者替代方案,谢谢。

1 个解决方案

#1


0  

It seems, ClientSecrets.load accepts optional argument which is config filename path. So I believe it's okay if you specify filename directly:

看来,ClientSecrets.load接受可选参数,即config filename path。所以我相信你可以直接指定文件名:

Google::APIClient::ClientSecrets.load("#{Rails.root}/config/client_secrets.json")

#1


0  

It seems, ClientSecrets.load accepts optional argument which is config filename path. So I believe it's okay if you specify filename directly:

看来,ClientSecrets.load接受可选参数,即config filename path。所以我相信你可以直接指定文件名:

Google::APIClient::ClientSecrets.load("#{Rails.root}/config/client_secrets.json")