I'm using the Sorcery gem and their external module to authenticate with Twitter. I've got the authentication working, but I want to store the user's Twitter profile image URL in my database after a successful log in. Sorcery seems to have a configuration option that's meant to do exactly what I want:
config.twitter.user_info_mapping = {:nickname => "screen_name"}
Maybe I've missed something in the Sorcery documentation, but I can't find any information about what "keys" are available. I tried this to no avail:
config.twitter.user_info_mapping = {:nickname => "screen_name", :avatar_url => "profile_image_url"}
Has anyone found documentation about this?
That is just what you get from twitter in json format.
Here is a twitter documentation about it https://dev.twitter.com/docs/api/1/get/account/verify_credentials
config.twitter.user_info_mapping = {:username => "screen_name",
:realname => "name",
:location => "place",
:web => "url",
:bio => "description"}
Related
I am currently developing a ruby on rails application which includes the gattica gem to fetch Google Analytics data. When I fetch my data:
https://github.com/activenetwork/gattica
gs = Gattica.new({:email => 'johndoe#google.com', :password => 'password', :profile_id => 123456})
results = gs.get({ :start_date => '2008-01-01',
:end_date => '2008-02-01',
:dimensions => 'browser',
:metrics => 'pageviews',
:sort => '-pageviews'})
on development I will simply receive a response which I can parse to my application.
However on production the page returns a 500 error and in my Gmail inbox I receive a message about a suspicious login being caught.
Is there any way I can fix this issue?
PS: my application is hosted on Heroku.
With kind regards,
Dennis
You're getting the 500 error because Google is blocking your heroku ip from accessing your account. They aren't sure it's you.
You need to change your activity settings to authorize that ip/domain.
Read this: https://support.google.com/accounts/answer/1144110?hl=en&ref_topic=2401957
Also, its a good idea to read your logs when debugging these kinds of errors. Rails.logger.debug results could shed some light.
Is Google API Ruby client the best option?
I have a site example.com with users and I want them to see their google analytics stats on example.com, how can I do it ?
I can see the example but I'm not able to figure out how to begin.
I also use the google-api-ruby-client gem and set it up about the same way that is outlined in the link you provided (https://gist.github.com/joost/5344705).
Just follow the steps outlined in the link to set up a Google Analytics client:
# you need to set this according to your situation/needs
SERVICE_ACCOUNT_EMAIL_ADDRESS = '...' # looks like 12345#developer.gserviceaccount.com
PATH_TO_KEY_FILE = '...' # the path to the downloaded .p12 key file
PROFILE = '...' # your GA profile id, looks like 'ga:12345'
require 'google/api_client'
# set up a client instance
client = Google::APIClient.new
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/analytics.readonly',
:issuer => SERVICE_ACCOUNT_EMAIL_ADDRESS,
:signing_key => Google::APIClient::PKCS12.load_key(PATH_TO_KEY_FILE, 'notasecret')
).tap { |auth| auth.fetch_access_token! }
api_method = client.discovered_api('analytics','v3').data.ga.get
# make queries
result = client.execute(:api_method => api_method, :parameters => {
'ids' => PROFILE,
'start-date' => Date.new(1970,1,1).to_s,
'end-date' => Date.today.to_s,
'dimensions' => 'ga:pagePath',
'metrics' => 'ga:pageviews',
'filters' => 'ga:pagePath==/url/to/user'
})
puts result.data.rows.inspect
To display statistics for a user's page in your app, you have to adjust the metrics and filters parameters when making the query. The query above for example will return a result object containing all pageviews for the page with url example.com/url/to/user.
Caveat: this answer was written a long time ago and Google released a new, incompatible version of the gem. Please consult https://github.com/google/google-api-ruby-client/blob/master/MIGRATING.md
I'm running Rails 3, with the LinkedIn API gem: here
I've been unable to get the Share API working as described here
This works fine:
response = client.add_share(:comment => 'new share API')
This Fails with:
response = client.add_share(:comment => 'new share API', :title => 'Linkedin Share API', :url => 'http://developer.linkedin.com/docs/DOC-1212', :image_url => 'http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg')
Error:
LinkedIn::Errors::GeneralError ((400): Invalid xml {Expected elements 'post-network-update#http://api.linkedin.com/v1 id#http://api.linkedin.com/v1 visibility#http://api.linkedin.com/v1 comment#http://api.linkedin.com/v1 attribution#http://api.linkedin.com/v1 content#http://api.linkedin.com/v1 private-message#http://api.linkedin.com/v1 share-target-reach#http://api.linkedin.com/v1' instead of 'image-url#http://api.linkedin.com/v1' here in element share#http://api.linkedin.com/v1, Expected elements 'post-network-update#http://api.linkedin.com/v1 id#http://api.linkedin.com/v1 attribution#http://api.linkedin.com/v1 content#http://api.linkedin.com/v1 private-message#http://api.linkedin.com/v1 share-target-reach#http://api.linkedin.com/v1' instead of 'url#http://api.linkedin.com/v1' here in element share#http://api.linkedin.com/v1}):
Any ideas? Thanks
You're doing it wrong. This is the XML in of sample request in https://developer.linkedin.com/documents/share-api#toggleview:id=xml
<share>
<comment>Check out the LinkedIn Share API!</comment>
<content>
<title>LinkedIn Developers Documentation On Using the Share API</title>
<description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>
<submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>
<submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url>
</content>
<visibility>
<code>anyone</code>
</visibility>
</share>
So the request should look something like this based in the sample request:
response = client.add_share(:comment => 'Sample Job',
:content => { :title => 'LinkedIn Developers Documentation On Using the Share API', :description => 'Leverage the Share API to maximize engagement on user-generated content on LinkedIn', :'submitted-url' => 'https://developer.linkedin.com/documents/share-api', :'submitted-image-url' => 'http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png' } )
I am currently developing a Rails web application that requires a user to login through LinkedIn. After that I want to embed the Member Profile plugin in his/her profile page.
For that to happen I need to have the public URL, without it the plugin will not work. I already have full profile permission r_fullprofile on LinkedIn login. But still I am not able to find the API to extract public url.
Is there a way to get that URL?
You can specify public-profile-url as a default field:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :linkedin, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]
end
and then using the pengwynn LinkedIn gem you can access the URL like so:
client = LinkedIn::Client.new
client.authorize_from_access("access_token", "access_token_secret")
client.profile(:fields => ["public-profile-url"])
I have a rails 3 app + devise using capybara for integration tests. Right now I have sign and sign up tests working but don't have tests for FB Connect.
How can I add Omniauth tests to ensure sign up and sign in work? Any one have an example or a up to date tutorial that shows how this is done? All I could find is fragments of info.
Thanks
I don't have the complete example. I added the following to my test.rb(You can add it to a initializer and add it if the enviroment is test).
OmniAuth.config.test_mode = true
FACEBOOK_INFO = {
"id"=> "220439",
"email" => "bret#facebook.com",
}
OmniAuth.config.mock_auth[:facebook] = {
"uid" => '12345',
"provider" => 'facebook',
"user_info" => {"name" => "Bret Taylor", "nickname" => 'btaylor'},
"credentials" => {"token" => 'plataformatec'},
"extra" => {"user_hash" => FACEBOOK_INFO}
}
This simulates the call to omniauth. So in your test, when you simulate a click to the facebook button, the response you will get is the one from OmniAuth.config.mock_auth[:facebook].