I am using the omniauth-facebook gem in rails 3 following the tutorial at http://blog.railsrumble.com/blog/2010/10/08/intridea-omniauth.
I am inspecting Facebook's response using
render :text => request.env['omniauth.auth']
Only the following is being returned:
# extra=#> info=#> provider="facebook" uid="12345678">
In other words, only the uid is being returned. I can't figure out why none of the other basic info is coming up for the user especially since the UID is showing up. Any ideas?
request.env['omniauth.auth'] is a hash made by Omniauth that contains all the data sent by the provider. It also contains another hash called extra which also contains another hash called raw_info - all the data sent (in this case) by Facebook's Graph API.
For example, you can access the user's email using
request.env['omniauth.auth']['extra']['raw_info']['email']
Source
Related
My users can login only by Twitter and I'm using the omniauth-twitter gem (https://github.com/arunagw/omniauth-twitter).
Rails 4.1.2 and Ruby 2.1.0
It works perfectly, the only problem is that whenever a user changes his profile photo or name, the database is not updated with the changes.
How can I make my app to see after every login if any of the attributes is changed and if so, to update the database with them?
Thank you very much.
You should be able to add some code to your twitter callback action -- the action that is called by the path /auth/twitter/callback -- to read from the OmniAuth::AuthHash that is returned to you via request.env['omniauth.auth']. Basically, omniauth-twitter packages up the OAuth Provider's response into a convenient objet and places it in the request hash. So... something like this:
def twitter
# ...
update_picture
end
def update_picture
auth = request.env['omniauth.auth']
current_user.picture = auth.info.image
# or whatever
end
FYI: The OmniAuth::AuthHash object is basically a hash with benefits. It is an instance of a Hashie object, in case you're interested in learning more. (Off the top of my head, I think it's a Mash hash.)
Also, you can find and example return response here, in the omniauth-twitter readme.
I have an FB account and i have created a fan page for my club and few other pages as well. I have an app in Ruby on Rails. I want to publish some feed on my club fan page. How can i do this?
I have been using Koala Gem and able to successfully post to my wall but not on to the page.
I want to access the list of all the fan pages associated with my account instead of giving the name of specific page.
here is my simple method which i am using to communicate to FB Graph API.
def facebook
#facebook ||= Koala::Facebook::GraphAPI.new(oauth_token)
rescue Koala::Facebook::APIError => e
logger.info e.to_s
nil # or consider a custom null object
end
Answer submitted by Sumit can be an approach but after searching around some more forums, finally i got an elegant way to do it.
#user_graph = Koala::Facebook::API.new(user_access_token)
pages = #user_graph.get_connections('me', 'accounts')
# get access token for first page
first_page_token = pages.first['access_token']
# or: retrieve access_token for a given page_id
page_token = #user_graph.get_page_access_token(page_id)
Passing on the "accounts" parameter to get_connection worked elegantly for me.
Here is the reference to API.
And one last thing, never forget to add the "manage_pages" permission in your permissions list.
I'm trying to set up the linkedin api in a rails 3 app using the linkedin gem. I don't want the user to have to authenticate my app in order for the API to get their info. I only need one piece of their public profile (the headline). So, maybe I should just be using xml or json to pull this off (not exactly sure how to get that with linkedin either).
I have the following in a helper so that I can call linkedin_header() in a loop of users. I only have 'client' as the last line of the following code while debugging. It outputs as expected (#). It seems like I am only a step away from success. How can I access a given users headline? I have tried using "client = client.profile(:url => 'linkedin_user_url')", but that return "Call must be made on behalf of a member".
def linkedin_header(account_user)
user = User.find(account_user)
account = Account.where(:user_id => user, :external_id => 1)
api_key = 'aaaaaaaa'
api_secret = 'bbbbbbbb'
client = LinkedIn::Client.new(api_key, api_secret)
rtoken = client.request_token.token # this returns correctly
rsecret = client.request_token.secret # this returns correctly
client
# client = client.profile(:url => 'linkedin_user_url')
end
So, I guess I have two questions. Is my request (public headline of any user) too simple for the above...should I be using XML or JSON. And, if Im close...can I make the API work for me without the user having to authenticate via linkedin.
Based off of what I read from the LinkedIn API reference (http://developer.linkedin.com/documents/authentication)
You have to make requests to their API only after being authenticated. (Using OAuth Keys) Rather than just grabbing the publicly available information.
It seems like since you want a small piece of information (the public headline of any user) you'd want some sort of implementation like Facebook's OpenGraph. After looking around on LinkedIn, I don't see any sort of public implementation like that.
I would suggest checking out this gem:
https://github.com/yatishmehta27/linkedin-scraper
It seems to be the type of solution you're looking for.
I'm using Omniauth to get credentials from Twitter for a specific User. Part of the OmniAuth object that I get is like this:
credentials=#
<Hashie::Mash secret="XXXX" token="XXXX">
extra=#<Hashie::Mash access_token=#<OAuth::AccessToken:xxxx #token="xxxx", #secret="xxxxx", ..
Right now I'm storing the credentials[token] and the UID for that specific User. At some point I want to fetch the Twitter API using the auth for that specific User to avoid getting the 150 max requests for a specific IP. Right now I'm just doing this:
twitter_user_name = Twitter.user(user_id).screen_name
So, how can I do to make those requests using the Twitter gem using the auth provided by OmniAuth instead of doing requests from my own IP (unauthenticated calls and therefore limited)
After playing with the gem, I've figured how to do it:
You want to create a new API object for a specific User, so you want to do this:
client = Twitter::Client.new(:oauth_token => 'XXXXX', :oauth_token_secret => 'XXXX')
And use this client to do the requests.
I am trying to develop a facebook integration to fetch the wall posts using KOALA Gem (1.1.0), and Rails 2.3.8 . I can easily generate user_access_token and page_access_token and able to get data using graph API. But when I am using realtime update I can't get datas which need access token. I can access all public information with KOALA api.
I guess we need to pass access_token(user_access_token or page_access_token). I couldn't find an option to pass access token. I checked the RealTimeUpdate class and found only two arguments app_access_token and app_id, which may not be sufficient to get the protected data like feeds and post
Here am attaching the sample code:
#updates = Koala::Facebook::RealtimeUpdates.new(:app_id => YOUR_APP_ID, :secret => YOUR_APP_SECRET )
=> Koala::Facebook::RealtimeUpdates:0x10331fb88 #graph_api=#, #secret=”81297xxxxxxxxxxx”, #app_access_token=”1779yyyyyyy|xxxxxxx”, #app_id=”1779yyyyy”
and you can see app_access_token and access_token has been set the same.
Then I tried to retrieve the access token as follows but it returns nil.
>> #updates.access_token
=> nil
Kindly advise how do I go forward?
Seems this is a bug in facebook . Please have a look #
http://bugs.developers.facebook.net/show_bug.cgi?id=18048