【问题标题】:Cannot load Google API Client on Ruby on Rails无法在 Ruby on Rails 上加载 Google API 客户端
【发布时间】:2018-01-10 11:15:20
【问题描述】:

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

但是当我尝试执行此步骤时

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 引发错误,提示“未提供 client_secrets.json 文件名和/或无法在搜索路径中找到。” 即使我在 config/client_secrets.json 中插入了 client_secrets.json 也会出现错误

您知道这个解决方案的问题或替代方案是什么吗,谢谢。

【问题讨论】:

    标签: android ruby-on-rails json ruby google-plus-signin


    【解决方案1】:

    It seems, ClientSecrets.load 接受可选参数,即配置文件名路径。所以我相信你直接指定文件名是可以的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多