Skip to content

Instantly share code, notes, and snippets.

@bcantin
Created August 15, 2010 00:02
Show Gist options
  • Save bcantin/524867 to your computer and use it in GitHub Desktop.
Save bcantin/524867 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'linkedin'
require 'yaml'
# use your key to create a client object
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret')
# store the rtoken and rsecret
rtoken = client.request_token.token
rsecret = client.request_token.secret
# now we want to get permission for our application to use linkedin for our profile
client.request_token.authorize_url
=> "https://api.linkedin.com/uas/oauth/authorize?oauth_token=<generated_token>"
# now you can get your access keys.
array = client.authorize_from_request(rtoken, rsecret, pin)
=> ["OU812", "8675309"] # <= save these for future requests
# Store them in a database or a yaml file
keys = {}
keys['key'] = array[0]
keys['token'] = array[1]
f = File.new('linkedin_data.yml','w')
f.puts YAML.dump(keys)
##
## NEW SESSION
##
require 'rubygems'
require 'linkedin'
require 'yaml'
# you can use your keys again in a new session
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret')
# read the file and use the keys
f = File.new('linkedin_data.yml','r')
keys = YAML.load(f.read)
client.authorize_from_access(keys['key'], keys['token'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment