Edgars
Edgars

Reputation: 953

How to start work with Gmail API in Rails 4

I would like to add Gmail to my Rails 4 app. So far I have set up everything so user can log in with Google account. I followed this guide.

Now when user tries to log in my Rails 4 app he receives such onscreen :

enter image description here After "Allow" user is redirected back to my Rails 4 app.

Initializers/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

All authorization data from Google is located in secrets.yml.

Installed gems:

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

Question: What are the next steps to implement Gmail API in Rails project? How to retrieve my Gmail inbox content.. So far I haven't found complete and self-explaining guide to do so.

I found Gmail gem, but the guide is very incomplete for Rails begginers.

For example, I installed this gem and then tried to require 'gmail' in rails c . Then I received error uninitialized constance 'gmail'.

Note: I don't need full solution to my problem,but just a push to start going and I could understand idea.

Thanks in advance.

Upvotes: 0

Views: 1533

Answers (1)

KENdi
KENdi

Reputation: 7771

Try to check the Ruby implementation of Gmail API in the Google Documentation itself. Just complete the steps described in the rest of this page, and you'll have a simple Ruby command-line application that makes requests to the Gmail API.

For more information, you can also check these threads:

Upvotes: 2

Related Questions