如何在Rails 4

时间:2017-01-13 14:41:22

标签: ruby-on-rails gmail-api

我想将Gmail添加到我的Rails 4应用中。到目前为止,我已经设置了所有内容,因此用户可以使用Google帐户登录。我遵循了guide

现在,当用户尝试登录我的Rails 4应用程序时,他会收到这样的屏幕:

enter image description here 在"允许"用户被重定向回我的Rails 4应用程序。

初始化器/ omioauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, Rails.application.secrets.client_id, Rails.application.secrets.client_secret, {scope: ['email',
    'https://www.googleapis.com/auth/gmail.modify'],
    access_type: 'offline', client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end

Google的所有授权数据均位于secrets.yml。

已安装的宝石:

gem "omniauth-google-oauth2", "~> 0.2.1"
gem "google-api-client"

问题:在Rails项目中实施Gmail API的后续步骤是什么?如何检索我的Gmail收件箱内容.. 到目前为止,我还没有找到完整且自我解释的指南。

我找到了Gmail gem,但对于Rails begginers来说,指南非常不完整。

例如,我安装了此gem,然后在require 'gmail'中尝试rails c。然后我收到错误uninitialized constance 'gmail'

注意:我不需要完全解决我的问题,但只是推动开始,我可以理解。

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试检查Google文档中的Ruby implementation Gmail API。 只需完成本页其余部分中描述的步骤,您就会拥有一个简单的Ruby命令行应用程序,可以向Gmail API发出请求。

有关详细信息,您还可以查看以下主题: