Making an API Call with an OAuth Token

The first thing you'll likely want to do is retrieve the profile for the member who just gave your application access. This involves making a simple request signed with the OAuth authentication information.

As an example, let's get a very basic version of this member's profile.

Python

This example uses the python oauth2 library.

import oauth2 as oauth
import time

url = "https://api.linkedin.com/v1/people/~"

consumer = oauth.Consumer(
     key="CONSUMER_KEY",
     secret="CONSUMER_SECRET")
     
token = oauth.Token(
     key="OAUTH_TOKEN", 
     secret="OAUTH_TOKEN_SECRET")


client = oauth.Client(consumer, token)

resp, content = client.request(url)
print resp
print content

With this you get a basic default profile for the currently signed-in user:

<?xml version=

"1.0" encoding="UTF-8" standalone="yes"?>
<person>
  <first-name>Kirsten</first-name>
  <last-name>Jones</last-name>
  <headline>Developer Advocate at LinkedIn</headline>
  <site-standard-profile-request>
    <url>https://www.linkedin.com/profile?viewProfile=&amp;key=3639896&amp;authToken=JdAa&amp;authType=name&amp;trk=api*a119686*s128146*</url>
  </site-standard-profile-request>
</person>

Ruby

The script attached to the Getting an OAuth Token in Ruby document goes through the process of executing a basic profile call once the token is retrieved.  The basic code for making a call once you've retrieved your token looks like the following.  If you need more details, refer back to the original Ruby document.

consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, consumer_options)
access_token = OAuth::AccessToken.new(consumer, oauth_token, oauth_secret)
# Pick some fields
fields = ['first-name', 'last-name', 'headline', 'industry', 'num-connections'].join(',')
# Make a request for JSON data
json_txt = access_token.get("/v1/people/~:(#{fields})", 'x-li-format' => 'json').body
profile = JSON.parse(json_txt)
puts "Profile data:"
puts JSON.pretty_generate(profile)

Congratulations!  You've now successfully made a signed request to the LinkedIn API.  You can find documentation for each of the API resources on our documentation page.  Please post any questions to our forums, and let everyone know when you have a cool LinkedIn app to share.  Have fun!