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 :
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.
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:
How to access the Gmail API with Ruby
google/google-api-ruby-client
Gmail API Client Library for Ruby
Gmail API and Rails – Authorize with OAuth via Omniauth
Related
I am having a rails project in which my client's requirement is to login user with yahoo So, I need to integrate user authentication using yahoo.
I am badly stuck due to limited resources in order to achieve this so finally I came on SO.
Well, after struggling much this code give me some hope but it is very basic level of startup and I dont know where and what to do now.
Here is my some code part:
client = OAuth2::Client.new(oauth_consumer_key,oauth_consumer_secret, {
access_token_path: '/oauth/v2/get_token',
authorize_path: '/oauth/v2/request_auth',
authorize_url: 'https://api.login.yahoo.com/oauth/v2/request_auth',
request_token_path: '/oauth/v2/get_request_token',
site: 'https://api.login.yahoo.com'
})
puts client.auth_code.authorize_url( redirect_uri: "http://lvh.me:3000")
code = gets.chomp
token = client.auth_code.get_token(code, redirect_uri: "http://lvh.me:3000")
OK so there are like a million tutorials about how to use Devise with OmniAuth. There is a gem for omniauth yahoo. This is my favorite tutorial for it: https://www.digitalocean.com/community/tutorials/how-to-configure-devise-and-omniauth-for-your-rails-application.
I would just use the yahoo gem instead of the digital ocean one they suggest.
Yahoo Gem: https://github.com/timbreitkreutz/omniauth-yahoo
Also refer to this SO question where he walks through an install with Facebook: How to use and configure omniauth with yahoo, google, facebook strategies in various environments?
I can't seem to find anything about migrating away from openid for omniauth users? Is this as simple as changing the redirect url?
require "openid/store/filesystem"
require "omniauth-google-oauth2"
config.omniauth :google_apps,
store: OpenID::Store::Filesystem.new('/tmp'),
domain: "example.com",
identifier: "https://www.google.com/accounts/o8/id"
I ended up using gem omniauth-google-oauth2.
The ReadMe explains how to set it up.
gem omniauth-google-apps is now deprecated and no longer maintained. It won't work after April 20, 2015 when google stops supporting openid.
I am using Omni auth gem to load twitter feeds into my application.
But when i try to load direct messages, its not letting the application to direct messages.
I researched and found that when adding a twitter account, usually the system takes us to
https://api.twitter.com/oauth/authenticate
but i found my applicatin could access direct message when the request made to twitter during twitter account add process will be like below
https://api.twitter.com/oauth/authorize
where do i configure this in Omniauth gem?
Please give me a hand on this.
thanks.
This can be done by adding client_options: {authorize_path: '/oauth/authorize'}
under config/initializers/omniauth.rb under provider :twitter.
SA
I have a application written in RubyonRails and I want to make him post periodically on facebook fan page.
I used fb_graph gem to do that.
I created my facebook app and I get my Access Token to use it but when I use this peace of code
me = FbGraph::User.me(ACCESS_TOKEN)
me.feed!(
:message => 'Updating via FbGraph',
:picture => 'https://graph.facebook.com/matake/picture',
:link => 'http://github.com/nov/fb_graph',
:name => 'FbGraph',
:description => 'A Ruby wrapper for Facebook Graph API'
)
I get permission denied error message.
How can I get the permission to post on my fan page wall?
Thanks in advance.
Link to the docs:
http://developers.facebook.com/docs/authentication/
There are several flows, but essentially, you provide a link for the client to authenticate at facebook:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=publish_stream,manage_pages
After authing this redirects to a URL on your site prepared to handle the param code, which you then turn around and send back to facebook for your access_token, which you provide to fb_graph.
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URLclient_secret=YOUR_APP_SECRET&code=CODE
There are other permissions as well, so you might want to check the facebook docs to see if there are more you need.
Facebook uses OAuth 2 for auth, and there are several ruby gems you can use to facilitate this process slightly, including the oauth2 gem.
The app ID you specified must be wrong. please cross check that. A sample appID looks like this
APP_ID="162221007183726"
Also check whether you have used any call back url. The url should point to a server. Your cannot use your localhost/ local IP there.
A similar nice rails plugin for Facebook app using Rails3 is Koala gem
https://github.com/arsduo/koala/wiki/Koala-on-Rails
http://blog.twoalex.com/2010/05/03/introducing-koala-a-new-gem-for-facebooks-new-graph-api/
I installed "contacts" gem on my local machine, wrote some code to get yahoo, gmail and hotmail contacts, and it was running smoothly. I moved the code to a server for testing, my gmail and hotmail contacts were still running, but Yahoo gave me the following error:
Contacts::AuthenticationError: Username and password do not match
I am sure that email and password are correct. I tried my code on another server the behavior was the same ...
Any hints?
This is because Yahoo contacts uses Oauth, not BBauth: https://github.com/mislav/contacts/issues/4
The turingstudio version of the gem is more up to date and it seems to support Yahoo Oauth.
Install it using bundler:
gem "turing-contacts", :git => "git://github.com/turingstudio/contacts.git"