Linkedin Permissions : only serving current position informations - ruby-on-rails

This question is related to the same one here, but still i am facing the same problem that linkedin is only serving the current position informations , how can i get the past positions & education details using the linkedin gem in Rails,my linkedin controller has been shown below, need your assistance.
require 'linkedin'
class LinkedinUserController < ApplicationController
def init_client
key = "XXXXXX"
secret = "XXXXXX"
linkedin_configuration = { :site => 'https://api.linkedin.com',
:authorize_path => '/uas/oauth/authenticate',
:request_token_path =>'/uas/oauth/requestToken?scope=r_basicprofile+r_fullprofile+r_emailaddress+r_network+r_contactinfo',
:access_token_path => '/uas/oauth/accessToken' }
#linkedin_client = LinkedIn::Client.new(key, secret,linkedin_configuration)
end
def auth
init_client
request_token = #linkedin_client.request_token(:oauth_callback => "http://#{request.host_with_port}/linkedin/callback")
session[:rtoken] = request_token.token
session[:rsecret] = request_token.secret
redirect_to #linkedin_client.request_token.authorize_url
end
def callback
init_client
if session[:atoken].nil?
pin = params[:oauth_verifier]
atoken, asecret = #linkedin_client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
session[:atoken] = atoken
session[:asecret] = asecret
else
#linkedin_client.authorize_from_access(session[:atoken], session[:asecret])
end
c = #linkedin_client
c.profile(:fields=>["first_name","last_name","headline","positions","educations"])
end
end

LinkedIn is very particular about access to profile fields and you cannot combine multiple fields which requires 2 different access.
so when you try to get just position details by c.profile(:fields => %w(positions)) it assumes the access of type 'r_basicprofile' whereas educations field require access of type 'r_fullprofile'.so try 2 seperate API calls to retrieve both fields.
"first_name","last_name","headline","positions" available for 'r_basicprofile' member permission,so they can be combined together.

Related

Get Input from form for API url Request in rails?

I'm new to Rails and I'm trying to make a simple weather API to get weather by zipcode
is there a way to get the zipcode from user input from a simple form, this will be just for learning so I'm not trying to make users devise, or users model
require 'net/http'
require 'json'
#url = 'http://api.openweathermap.org/data/2.5/weather?zip=#{zipcode}&appid=APIKEY'
#uri = URI(#url)
#response = Net::HTTP.get(#uri)
#output = JSON.parse(#response)
actually I figured it out, i needed to add
def zipcode
#zip_query = params[:zipcode]
if params[:zipcode] == ""
#zip_query = "Hey you forgot to enter a zipcode!"
elsif params[:zipcode]
# Do Api stuff
require 'net/http'
require 'json'
#url = 'http://api.openweathermap.org/data/2.5/weather?zip='+ #zip_query +'&appid=APIKEY'
#uri = URI(#url)
#response = Net::HTTP.get(#uri)
#output = JSON.parse(#response)
#name = #output['name']
# Check for empty return result
if #output.empty?
#final_output = "Error"
elsif !#output
#final_output = "Error"
else
#final_output = ((#output['main']['temp'] - 273.15) * 9/5 +32).round(2)
end
end
end
in the controller.rb file
and add
post "zipcode" => 'home#zipcode'
get "home/zipcode"
in the routes file
but I'm sure this is not the best practice

How to get OpenStreetMap access token with devise omniauth-osm

In my controller, I'm trying to get an access token to OSM.
class Auth::OauthController < Devise::OmniauthCallbacksController
def osm
#user = AppUser.from_omniauth(request.env["omniauth.auth"])
token_req = request.env["omniauth.auth"]['extra']['access_token'].consumer.get_request_token(:oauth_verifier => params['oauth_verifier'])
#user.token = token_req.token
#user.token_secret = token_req.secret
sign_in_and_redirect #user
end
end
When I get the access token and writes it to the database.
Next, I try to use the OSM API through oauth gem.
#consumer=OAuth::Consumer.new Settings.osm.consumer_key,
Settings.osm.consumer_secret,
{site: osm_uri}
#access_token = OAuth::AccessToken.new(#consumer, current_user.token, current_user.token_secret)
puts #access_token.get('/api/0.6/user/preferences').body
However, this code does not work in the console I see the authorization error
the error in this code:
token_req = request.env["omniauth.auth"]['extra']['access_token'].consumer.get_request_token(:oauth_verifier => params['oauth_verifier'])
#user.token = token_req.token
#user.token_secret = token_req.secret
correct code
#app_user.token = request.env["omniauth.auth"]['credentials']['token']
#app_user.token_secret = request.env["omniauth.auth"]['credentials']['secret']

How to retrieve reference to AWS::S3::MultipartUpload with ruby

I have a rails app and in a controller action I am able to create a multipart upload like so:
def create
s3 = AWS::S3.new
bucket = s3.buckets["my_bucket"]
key = "some_new_file_name.ext"
obj = bucket.objects[key]
mpu = obj.multipart_upload
render json: {
:id => mpu.id
}
end
so now the client has the multipart upload id and she can upload parts to aws with her browser. I wish to create another action which will assemble the parts once they are done uploading. Something like:
def assemble
s3 = AWS::S3.new
bucket = s3.buckets["my_bucket"]
key = params['key']
bucket.objects[key].multipart_upload.complete
render json: { :status => "all good" }
end
This isn't working though. How do I retrieve a reference to the multipartUpload object or create a new one with the key or id so that I can call the "complete" method on it? Any insight is appreciated
I found this method in the documentation for the Client class and got it to work as follows:
client = AWS::S3::Client.new
# reassemble partsList
partsList = []
params[:partsList].each do |key, pair|
partsList.push pair
end
options = {
:bucket_name => 'my_bucket',
:key => params[:key],
:upload_id => params[:upload_id],
:parts => partsList
}
client.complete_multipart_upload(options)

Why Importing gmail contacts using Omnicontacts takes only 99 contacts

I am using omnicontacts to import contacts from gmail. But It takes only 99 contacts not all.
Here is my code
def contacts_callback
#contacts = request.env['omnicontacts.contacts']
#contacts.each do |contact|
contact1 = current_user.contacts.new
contact1.name = contact[:name]
contact1.email = contact[:email]
contact1.group = "Others"
contact1.save(:validate => false)
end
redirect_to "/contact"
end
I can't figure out problem. Please help.
You need to add the max_contacts option in your initializer:
importer :gmail, "xxx", "yyy", :max_results => 1000
I have just updated the README to include this.
Solved it :)
I went to lib/omnicontacts/importer/gmail.rb
def initialize *args
super *args
#auth_host = "accounts.google.com"
#authorize_path = "/o/oauth2/auth"
#auth_token_path = "/o/oauth2/token"
#scope = "https://www.google.com/m8/feeds"
#contacts_host = "www.google.com"
#contacts_path = "/m8/feeds/contacts/default/full"
#max_results = (args[3] && args[3][:max_results]) || 100
end
And I just change #max_results 100 to 500. Now its working

How to get user profiles using ROR+linkedin

hi I am trying to get user profile information like this once the authentication is successful,
class LinkController < ApplicationController
def callback
client = LinkedIn::Client.new("ddddd", "ffffff")
if session[:atoken].nil?
pin = params[:oauth_verifier]
atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
session[:atoken] = atoken
session[:asecret] = asecret
else
client.authorize_from_access(session[:atoken], session[:asecret])
end
#profile = client.profile
#connections = client.connections
puts client.profile(:fields => [:positions]).positions
puts client.connections
end
end
the result i get is as follows:
#<LinkedIn::Profile:0x4a6fdd8>
#<LinkedIn::Profile:0x4a58f30>
#<LinkedIn::Profile:0x4a58af8>
#<LinkedIn::Profile:0x4a58708>
#<LinkedIn::Profile:0x4a583a8>
I really don't understand what is this and if the information is correct than how to convery it to user readable,
I am new guy to ROR please help me to get this resolved.
Those are objects; use the inspect method to return a human-readable representation:
client.profile.inspect

Resources