I am making a simple app in Ruby I need to get User's Email. I am using Google API client for Ruby. I am not able to get User's Email address, I have been researching on this topic for 2 days, and not able to get Email of user after the user sign in. I dont want to do it with Google+ sign in button I want it programmatically. I get authorized by google but then dont know how to retrieve the User Info of signed in user. I tried also tried it with client = Google::APIClient.new but i was not able. Below is my Code. I will appreciate your help.
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')
Hey On this You can Refer the Gem Google Plus
I have implemented the same and It's Working Fine from these sides.
Steps to Integrate Following Gem-
Firstly Install the google_plus gem by including it on GemFile.
Generate the API Key from Google Console of Google Plus +
https://console.developers.google.com
Including it Before use like it
GooglePlus.api_key = 'your key'
Search any Person by Id of Google
person = GooglePlus::Person.get(123)
You will get the complete users info for particular users
Related
I'm creating a authentication page on ionic 4 and I need to integrate the google auth to make the process easier.
But I don't want to store the users on firebase, because I have a backend on ruby on rails 5 application.
How to integrate google auth with rails api?
If you have the backend builded in rails you will need to validated the google auth first in the ionic app as explained in here. https://ionicthemes.com/tutorials/about/ionic-google-login#authentication-options you have 3 options, your is The handcrafted way (using your own API/Backend).
After get the authorization token from google you have to send it through your api and validates the token. To validate the token use the gem google-id-token and the your controller should looks like this
token = params[:token]
validator = GoogleIDToken::Validator.new(expiry: 1800)
begin
payload = validator.check(token, client_id)
user_id = payload['sub']
email = payload['email']
picture = payload['picture']
name = payload['name']
head :ok
rescue GoogleIDToken::ValidationError => e
head 404
end
For more information about this gem https://github.com/google/google-id-token
Also for the client_id it should be generated when you create an app in google console.
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 know that there is Koala gem for Rails to work with Facebook. I need to make clear 2 things:
How to check if some access_token is valid in Rails using Koala (or something else)?
How to generate some real access token (using some settings of my app or my login/password) for testing through RSpec?
Thanks in advance.
For #1 Use the Tool https://developers.facebook.com/tools/debug if you don't want to code a test. Otherwise hit this API and verify the response.
https://graph.facebook.com/oauth/access_token_info?client_id={APP_ID}&access_token={ACCESS_TOKEN}
For #2, Koala has a good API for accessing Facebook Test Users, which I recommend for use in Rspec.
We also support the test users API, allowing you to conjure up fake
users and command them to do your bidding using the Graph or REST API:
#test_users = Koala::Facebook::TestUsers.new(:app_id => id, :secret => secret)
user = #test_users.create(is_app_installed, desired_permissions)
user_graph_api = Koala::Facebook::API.new(user["access_token"])
# or, if you want to make a whole community:
#test_users.create_network(network_size, is_app_installed, common_permissions)
You can also create Test User in the App Settings from Facebook, and view thier details from this API :
https://graph.facebook.com/{APP_ID}/accounts/test-users?%20access_token={APP_TOKEN}
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 am currently trying to use this gem http://github.com/pengwynn/linkedin. Everything works fine (i.e. authentication and calling the method which gets the profile), except that the profile object only contains the first name and the last name.
I'm trying to get my own profile info through the LinkedIn API, So the necessary information is there. How to do that?
Thank you.
I just found out that in order to get more info rather that first name and last name, one needs to pass in the :fields param specifying the desired fields.
Link LinkedIn into your next Ruby application
Example from the site:
# get a profile for someone found in network via ID
client.profile(:id => 'gNma67_AdI', :fields => %w(first-name, last-name, headline, positions, education))
By design, the LinkedIn api does not give you the person's email address. (Unlike the Google oauth api).
What you can get from the LinkedIn api is information about the person's connections (friends) and more. See overview. Their profile api
Added: could be that the Rails LinkedIn gem does not yet expose all of the LinkedIn Profle api. That api has changed relatively recently. It may be that you'll need to find another gem or write you own sw to do it. Check on the LinkedIn api forum