Overview

JavaScript SDK

Initializing the Framework

JavaScript
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
  api_key:    [API_KEY]
  onLoad:     [ONLOAD]
  authorize:  [AUTHORIZE]
</script>

Parameters

  • API_KEY (required) Your API key.
  • ONLOAD (optional, comma-separated) The names of JavaScript functions which should be invoked once the framework has finished loading.
  • AUTHORIZE (optional, boolean, default=false) If false, then the framework will not automatically check to see if API access is available for the current user. If true, then the framework will check (based on the user's cookie) and if API access is available, then an oauth token will be retrieved automatically. In other words, if you set authorize: true, then the framework will attempt to auto-login the user.

LinkedIn Resource APIs

The JavaScript SDK is intended to be a thin wrapper over the normal LinkedIn REST APIs. Eventually, any call you can make using our traditional OAuth 1 REST model should be possible directly from client-side JavaScript with a native JS interface (and JSON results). We currently offer the following LinkedIn API Resources directly in the JavaScript SDK:

  • Connections
    Retrieve the current user's list of connections
  • MemberUpdates
    Retrieve a chronological view of a single user's updates
  • NetworkUpdates
    Retrieve updates from across the current user's entire network. This is similar to the timeline view seen on the LinkedIn home page.
  • PeopleSearch
    Search LinkedIn's database of over 200 million professionals
  • Profile
    Retrieve profile data for a LinkedIn member
  • Raw
    Perform a raw API query

Though they return different types of data, all the APIs above support a common interface of the following chained methods:

  • result(resultCallback, resultScope)
    Fires the API call. Invokes the function specified as resultCallback (optionally in the scope of resultScope). If resultScope isn't specified, the window scope is used. If called with no arguments, the call will fire but the result will not be available.
  • error(errorCallback, errorScope)
    Fires the API call. If an error occurs, errorCallback is invoked with a payload describing the error (optionally in the scope of errorScope). If called with no arguments, the call will fire but the result will not be available.
  • method(methodType)
    Can be used to override the method's default action (POST/GET). When an API makes use of the method method, it will be listed in the standard supported methods. methodType is a string for the HTTP action to take.
  • body(bodyContent)
    Can be used to override the method's posted body content. When an API makes use of the body method, it will be listed in the standard supported methods. bodyContent is a URL encoded post string.
  • params(paramObject)
    Some APIs allow for parameters to be passed as part of a query string, such as count or start. When an API makes use of the params method, it will be listed with the standard supported methods. paramObject is a set of key/value pairs to transmit with the API call. To pass multiple values for the same parameter name, make your value an array instead of a string. (For example: "type": ["SHAR", "APPS"])

In addition to these standard methods, some of the APIs accept parameterization in their constructor which is described below.

IN.API.Connections()

At present, you are only permitted to retrieve connections data for the currently signed-in member. A .ids() method exists, but is redundant in this API. 

JavaScript
IN.API.Connections("me").fields(fields).result(resultCallback)

IN.API.Connections.ids("me").fields([field1, field2]).params({param1:value, param2:value}).result(resultCallback)

IN.API.Connections("me").fields([field1, field2]).result(resultCallback)
  • default ids() - Array {String}, Argument List {String}
    Can only be called with the parameter "me".
  • fields() (optional) - Array {String}, Argument List {String}
    Specifies the profile fields to retrieve. If not specified, the default fields will be the server supplied defaults, subject to change. See Profile Fields for information about supported fields.
  • params() (optional) Object with parameters to pass to the backend call. See the Connections API documentation for information about supported parameters.

Examples

JavaScript
IN.API.Connections("me").result(doMyThing)

IN.API.Connections("me").fields("headline","first-name").result(function(result) { alert JSON.stringify(result)) }

IN.API.Connections("me").params({"count":1}).result(function(result) { alert JSON.stringify(result)) }

IN.API.MemberUpdates()

JavaScript
IN.API.MemberUpdates(ids).fields(fields).result(resultCallback)

IN.API.MemberUpdates().ids(id1, id2, id3).fields(field1, field2, field3).result(resultCallback)

IN.API.MemberUpdates().ids([id1, id2]).fields([field1, field2]).result(resultCallback)
  • default ids() - Array {String}, Argument List {String}
    Specifies the IDs to retrieve
  • fields() (optional) - Array {String}, Argument List {String}
    Specifies the fields to retrieve. If not specified, the default fields will be the server supplied defaults, subject to change. See Get Network Updates and Statistics API for information about the returned fields.
  • params() (optional) Object with parameters to pass to the backend call. See Get Network Updates and Statistics API for information about supported parameters.

Examples

JavaScript
IN.API.MemberUpdates("me").result(doMyThing)

IN.API.MemberUpdates("me").fields(["isLiked","updateContent:(person:(headline,first-name))"]).result(domything)

IN.API.MemberUpdates("me").params({"count":1}).result(function(result) { alert JSON.stringify(result)) }

IN.API.NetworkUpdates()

The infrastructure only allows for the calling of NetworkUpdates for the currently logged in user. A .ids() method exists, but is redundant in this API. 

JavaScript
IN.API.NetworkUpdates().fields(fields).result(resultCallback)
  • default ids() - Array {String}, Argument List {String}
    Can only be called with the parameter "me". Network Updates can only be retrieved for the currently logged in user
  • fields() (optional) - Array {String}, Argument List {String}
    Specifies the fields to retrieve. If not specified, the default fields will be the server supplied defaults, subject to change. See Get Network Updates and Statistics API for information about the returned fields.
  • params() (optional) Object with parameters to pass to the backend call.  See Get Network Updates and Statistics API for information about supported parameters.

Examples

JavaScript
IN.API.NetworkUpdates("me").result(doMyThing)

IN.API.NetworkUpdates("me").fields(["isLiked","updateContent:(person:(headline,first-name))"]).result(doMyThing}

IN.API.NetworkUpdates("me").params({"count":1}).result(function(result) { alert JSON.stringify(result)) 

IN.API.PeopleSearch()

This API does not currently provide access to search facet data. To access facet data, consider using the Raw API. Note the absence of any identifier - a People Search is conducted across the entire LinkedIn network from the perspective of the currently signed-in member. 

JavaScript
IN.API.PeopleSearch().fields(fields).params(paramsObject).result(resultCallback)

IN.API.PeopleSearch().fields(field1, field2, field3).params(paramsObject).result(resultCallback)

IN.API.PeopleSearch().fields([field1, field2]).params(paramsObject).result(resultCallback)
  • fields() (optional) - Array {String}, Argument List {String}
    Specifies the fields to retrieve based on the Profile API. If not specified, the default fields from the server will be used, subject to change.  A full list of available fields can be found in Profile Fields.
  • params() (optional) - Object
    The key/value pairs to use as parameters for the search. A full list of parameters is available in the People Search API documentation.

Example

JavaScript
IN.API.PeopleSearch().params({}).(result(doMyThing))

IN.API.PeopleSearch().fields(["firstName","lastName"]).result(function(result) { alert JSON.stringify(result)) }

IN.API.PeopleSearch().params({"first-name":"Kirsten","postal-code":"95030"}).result(function(result) { alert JSON.stringify(result)) }

IN.API.Profile()

JavaScript
IN.API.Profile(ids).fields(fields).result(resultCallback)

IN.API.Profile().ids(id1, id2, id3).fields(field1, field2, field3).result(resultCallback)

IN.API.Profile().ids([id1, id2]).fields([field1, field2]).result(resultCallback)
  • default ids() - Array {String}, Argument List {String}
    Specifies the IDs to retrieve
  • fields() (optional) - Array {String}, Argument List {String}
    Specifies the fields to retrieve. If not specified, the default fields will be used: "id", "firstName", "lastName", "headline", "pictureUrl".  A full list of available fields can be found in Profile Fields.

Examples

JavaScript
IN.API.Profile("me").(result(doMyThing))

IN.API.Profile("12345").fields(["firstName","lastName"]).result(function(result) { alert JSON.stringify(result)) }

IN.API.Raw()

This API provides raw support for APIs which are not available through the standard JavaScript SDK yet. This includes any requests using a method other than GET, such as POST, PUT, and DELETE.

JavaScript
IN.API.Raw(url).method(methodType).body(bodyContent).result(resultCallback)

IN.API.Raw().url(url).method(methodType).body(bodyContent).result(resultCallback)
  • default url() - String
    The API URL to invoke: should not include https://api.linkedin.com/v1.
  • method() - String
    The HTTP method to use (GET, POST, PUT, or DELETE). If omitted, uses a default value of GET.
  • body() - String
    For APIs with a POST body, POSTs and PUTs, this is the URL encoded post body. For GET requests, this does nothing.

For example, a People Search API call returning facet data for people living in the SF Bay Area:

JavaScript
IN.API.Raw("/people-search:(facets:(code,buckets:(code,name,count)))?facets=location&facet=location,us:84)")
      .result(function peopleSearchCallback(result) { /* code */ });

Or to update your current status:

JavaScript
var status = "Updating my status using the JavaScript API";
IN.API.Raw("/people/~/current-status").method("PUT").body(JSON.stringify(status))
      .result(function statusUpdateCallback(result) { /* code */ });

See the Sending JSON data section of API Requests with JSON for how to format the contents of the data passed to the body() method.

Use JSON.stringify() to convert the contents of a JavaScript variable -- string, array, hash -- to a JSON string.

The User Object

Allows manipulation of the User Object, such as authorizing, logging out, or refreshing the user's session.

Check if the User Is Authorized

You can use the isAuthorized method to see if the user has granted access to your application

JavaScript
IN.User.authorize(callbackFunction, callbackScope)

It returns a boolean true if the user is authorized, otherwise it returns false.

Request Authorization

You can request additional privileges by requiring the user to authorize. It's recommended to call this method in response to a user action to avoid popup blockers. If the user is not logged in, it will present the popup authorization window. 

JavaScript
IN.User.authorize(callbackFunction, callbackScope)
  • callbackFunction - Function
    a function to call when the user is authorized. If the user is already logged in, callbackFunction will fire immediately
  • callbackScope - Object
    an optional scope to run callbackFunction in. Defaults to the window scope

Log the User Out

You can log the user out of your application using the following code. In the JavaScript SDK, logging the user out is defined as logging them out of the LinkedIn network (i.e. clearing cookies). This does not &nbsp;revoke or delete the user's authorization grant for your application. 

JavaScript
IN.User.logout(callbackFunction, callbackScope)
  • callbackFunction - Function
    a function to call when the user is logged out.
  • callbackScope - Object
    an optional scope to run callbackFunction in. Defaults to the window scope

Refresh the User Session

The default user session is 30 minutes (after which the OAuth token expires). If you want to be sure the user is authorized and that your environment has a valid OAuth token, you can request a refresh of the user's session:

JavaScript
IN.User.refresh()

This will refresh their token for an additional 30 minutes. This call shouldn't be used to keep the user perpetually logged in, since that can introduce a security hole. 

Parsing Tags

As the framework loads, it will automatically scan the document and render any LinkedIn-specific tags. Occasionally, you may dynamically change the contents of the DOM and new LinkedIn tags need to be parsed. If the platform has already loaded, you can re-parse for IN tags with the following JavaScript:

JavaScript
IN.parse(domNode)

Where domNode is the node whose contents should be parsed (e.g. use document.body to trigger a re-parse of the entire page).

Events

Events provide a way for the developer to hook into interesting moments within the JavaScript SDK. These include user session state changes, as well as when the framework is loaded. All events are subscribed to through the same universal Event API:

JavaScript
IN.Event.on(IN, eventName, callback, callbackScope, extraData)
    
IN.Event.onOnce(IN, eventName, callback, callbackScope, extraData)

Invoking onOnce will limit the event's callback to happening a single time.

  • IN
    This is the global IN object, the root namespace of the LinkedIn JavaScript SDK. This means you want to listen to the framework's global events. In the future, it may be possible to subscribe to events from specific components.
  • eventName - String
    This is the name of the event. Supported events are:

    auth - The user has authorized this application

    frameworkLoaded - Fires before systemReady when all foundation JavaScript has been loaded from platform.linkedin.com. Usage for this event is intended to be internal-only for now.

    logout - The user has logged out of the application

    systemReady - Fired with the system is completely ready for execution. onLoad events can fire
  • callback - Function
    A callback function to execute when eventName fires
  • callbackScope - Object
    An optional scope to execute callback in. If not set, will default to the window scope
  • extraData - Object
    Provide an additional object to callback. If not set, will default to {}

Invoking UI Objects Directly

The UI elements can be invoked directly to open windows for the user to interact with LinkedIn. Many of these UI elements are spawned by either User actions or IN Tags. It's recommended that, to avoid popup blockers, all UI calls be in response to a user action such as clicking on an element.

All UI elements have the following methods:

  • params()
    Takes a key/value object definition that serves as parameterization for the widget.
  • place(domNode)
    Creates the UI element and inserts it into the document at the specific domNode. If domNode isn't specified, document.body is used
  • place(relative, domNode)
    Place the UI element relative to domNode. Valid values for relative are "in", "before", and "after"

Authorize

Opens an authorization window.

JavaScript
IN.UI.Authorize().place()

Share

Opens a LinkedIn Share window so that the current member can share a URL with his professional network:

JavaScript
IN.UI.Share().params({
  url: "http://www.example.com"
}).place()
  • url - String
    The url to share with LinkedIn Members

Supported Browsers

The JavaScript SDK supports the following browsers:

  • Firefox 3
  • Chrome
  • Safari 5
  • IE 6/7/8

IE 6 support may be deprecated in the future.