-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_linkedin.rb
27 lines (22 loc) · 975 Bytes
/
test_linkedin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'json'
require './config.rb'
require 'oauth'
# Fill the keys and secrets you retrieved after registering your app
api_key = $config[:linkedin][:api_key]
api_secret = $config[:linkedin][:api_secret]
user_token = $config[:linkedin][:user_token]
user_secret = $config[:linkedin][:user_secret]
# Specify LinkedIn API endpoint
configuration = { :site => 'https://api.linkedin.com' }
# Use your API key and secret to instantiate consumer object
consumer = OAuth::Consumer.new(api_key, api_secret, configuration)
# Use your developer token and secret to instantiate access token object
access_token = OAuth::AccessToken.new(consumer, user_token, user_secret)
# Make call to LinkedIn to retrieve your own profile
response = access_token.get("http://api.linkedin.com/v1/companies?email-domain=#{ARGV[0]}&format=json")
unless response.code == '200'
puts "HTTP error: #{response.code}"
exit
end
body = JSON.parse(response.body)
puts JSON.pretty_generate(body)