General Methods
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
IN.User.isAuthorized()
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.
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 API, logging the user out is defined as logging them out of the LinkedIn network (i.e. clearing cookies). This does not revoke or delete the user's authorization grant for your application.
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:
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.
Authorization Tokens
While the easiest method of authenticating a user for the JSAPI is to use one of the login buttons, some sites have implemented the OAuth 1.0a flow used by the REST API. Whichever type of authentication you use for the user, the JSAPI will recognize that the member has already logged in, as long as the key and hostname are the same. This happens automatically, requiring no additional code by the developer.
If a user has logged in using the JSAPI, a permanent token for the REST APIs can be generated from the JSAPI token. Details on this process are available in the document Exchange JSAPI Tokens for REST API OAuth Tokens.
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 new IN tags with the following 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 API. 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:
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 API. 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.
IN.UI.Authorize().place()
Share
Opens a LinkedIn Share window so that the current member can share a URL with his professional network:
IN.UI.Share().params({
url: "http://www.example.com"
}).place()
- url - String
The url to share with LinkedIn Members
Async Loading
To avoid encountering race conditions in your page, you can load the framework asynchronously.
If your page uses JQuery, the following code will work:
$(document).ready(function() {
$.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
IN.init({
onLoad: "myOnloadFunction"
});
});
});
Otherwise, you need something like this:
<script type="text/javascript" src="http://platform.linkedin.com/in.js?async=true"></script>
<script type="text/javascript">
IN.init({
onLoad: "myOnloadFunction"
// any other parameters you'd normally put beneath the script element would be here
});
</script>
Documentation
- Tutorials
- Javascript API Reference
- Overview
- Configuration and Compatibility
- IN.API.Profile()
- Making API Requests using IN.API
- IN.API.Connections()
- IN.API.PeopleSearch()
- IN.API.MemberUpdates() and IN.API.NetworkUpdates()
- IN.API.Raw()
- Tags and Templates
- IN.Auth, IN.Event, and IN.UI
- General Methods
- Exchange JSAPI Tokens for REST API OAuth Tokens
- Plugins
- Publisher Guidelines