无法从 google api 在 Ruby 中获取用户信息

Not able to get Userinfo from google api in Ruby

我正在 Ruby 中制作一个简单的应用程序,我需要获取用户的电子邮件。我正在为 Ruby 使用 Google API 客户端。我无法获取用户的电子邮件地址,我已经研究了 2 天这个主题,并且在用户登录后无法获取用户的电子邮件。我不想使用 Google+ 登录按钮我想要它以编程方式。我获得 google 的授权,但不知道如何检索已登录用户的用户信息。我也尝试过 client = Google::APIClient.new 但我做不到。以下是我的代码。我会感谢你的帮助。

scopes =  ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly', 'https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email']
  client_secrets = Google::APIClient::ClientSecrets.load(SECRETS_PATH)
  auth_client = client_secrets.to_authorization
  auth_client.update!(
      :additional_parameters => {"access_type" => "offline"}
  )
  auth_client.update!(
      :scope => scopes,
      :redirect_uri => 'http://localhost:3000/google_oauth2')

嘿嘿这个你可以参考GemGoogle Plus

我已经实施了相同的方法,并且从这些方面来看效果很好。

集成步骤如下 Gem-

  1. 首先安装 google_plus gem,将其包含在 Gem 文件中。

  2. 从 Google 控制台 Google Plus +

    生成 API 密钥

    https://console.developers.google.com

  3. 包含在使用前点赞

    GooglePlus.api_key = 'your key'
    
  4. 按 Google

    的 ID 搜索任何人
    person = GooglePlus::Person.get(123)
    

您将获得特定用户的完整用户信息