It’s been a while now that we were searching for a working ColdFusion LinkedIn API that would let users not only to receive data, but to submit some too. Although there were optional libraries such as linkedin-j, not everyone knows or wants to dip into the pure java world. Thanks to Derek Bowes, we stumbled across the LinkedIn.cfc which was a great plugin. The only trouble was that the plugin was already out of date since LinkedIn had updated their API in the second half of 2012, and now required member permissions were no longer a part of the original source code (plugin was last updated in July 2011).
So we took the initiative to our hands and amended the plugin to allow users set the permissions required as well as the ability to post status updates.
Here’s a quick step-by-step guide how to implement the updated plugin to your site:
Before you start, please note that this plug-in will only work on the ColdFusion 10 and above.
- new LinkedIn App:
Create a new app using your LinkedIn account at the following link:
Here you’ll have to select "Add New Application" and complete a not so complex form.
Note: you do not need to provide OAuth 1.0 Accept Redirect URL, as we’ll be setting it up inside our component in later steps. Oauth 1.0 Cancel Redirect URL is optional.
- API and Secret keys:
Once you’re done with the form and are looking at the new app’s confirmation page, take a note of the application API key and Secret key. We’ll need those later for your new app to function properly.
- Download our plugin:
Now that you are done with the setup of the new app on the LinkedIn’s side, it is time to download the plugin from us.
Step 4 - plugin setup:
Inside the downloaded archive there are four files:
There are no changes required to the index.cfm or getRequestToken.cfm files.
Open CallBack.cfm file and update the links where you would like user to be redirected to should the authorisation succeed or fail. This file is now ready.
Open LinkedIn.cfc file. Here you will need to update the following information:
- variables.callback - set this to the full URL of your callback
- variables.apiKey - enter your LinkedIn app key from the Step 2
- variables.secretKey - enter your LinkedIn app secret from the Step 2
- variables.permissions - enter permissions required, separated by ";".
You can find more information on available permissions here: http://developer.linkedin.com/documents/authentication
Step 5 - store access token and access secret [optional]
If you’d like to provide an ongoing LinkedIn service and do not want your user to be repeatedly asked to authorise the app everytime your website is visited, you can store the access token and access secret in the database and reuse it everytime the call is being made. If you wish to do so, the best practice would be performing such action inside the CallBack.cfm page. Insert your database call right before the first cflocation tag and save the following variables to it:
Now everytime user logs in to your website pull out the values from the database and you are good to go.
Step 6 - setup login page:
Now all that’s left to do is to place a link on your page, asking user to authorise your app and access to his/hers LinkedIn account.
At this point you’re done with the plugin setup and ready to have a look at the available get/post functions.
Permission required - r_network
This method gets all of the connections for the user. To call this method use the following code:
There are two optional variables, that can be passed to this method:
- start - starting location within the result set for paginated returns. Ranges are specified with a starting index and a number of results (count) to return
- count - ranges are specified with a starting index and a number of results to return. You may specify any number.
Here’s an example with the range parameters included in the call:
Details about the ’connections API’ can be found here:
Permission required - rw_nus
This method gets all or selected network updates for the user. To call this method use the following code:
The type variable is optional and can be left out from the call to receive all of the updates. However, if you do specify which network updates to receive, please separate them with commas. All available update types can be found at the link of the network updates and statistics API below.
These are the extra optional variables that can be passed to this method:
- count - Maximum number of updates to return
- start - The offset by which to start Network Update pagination
- after - unix timestamp after which to retrieve updates for (Ex: 1243834824)
- before - unix timestamp before which to retrieve updates for (Ex: 1243834824)
Permission required - r_basicprofile or r_fullprofile
This method gets profile information for the current user or, if specified, for any user by member id. To call this method use the following code:
There’s an optional variable - ’identifier’. Please do not include it in the call if you would like to receive profile information of the current user. Otherwise please specify either public URL or ID of the profile you would like to receive details about. Please note only profiles within person’s three degree network will be returned.
Details about the ’profile API’ can be found here:
Permission required - rw_nus
This method allows application to post status update on behalf of the user. To call this method use the following code:
Please note postTitle, postDescription, postURL, postImageURL and postVisibility variables are optional. To make a simple status update you are required to pass only postComment variable (along with the authToken and authTokenSecret). The remaining variables are here should you decide to share a link.
Details about the ’share API’ can be found here:
See the demo here:
The original Linkedin.cfc was created by Derek Bowes and can be found here:
Massive thanks to Derek for providing us with the great base!
And that is it! If you have any questions or comments, please use the comment section below.