0

I have a personal blog and I want to populate the "about me" section with my Linkedin data.

What's the best way to programmatically login to Linkedin with my own credentials and serve up the data?

I don't want vistors having to login to linkedin to be able to see "MY" linkedin data.

Any idea on the best approach for this?

This is the start of my code, I'm just starting out and getting an understanding of the flow.

(function($, window) {
"use strict";

var Linkedin = {
    Config: {
        API_KEY: "API_KEY",
        SECRET_KEY: "SECRET_KEY",
        URL: "http://www.hanger-designs.co.uk:8888/wemustcreate/",
        END_POINT: "http://platform.linkedin.com/in.js"
    },
    initalise: function() {
        this.insertScript(this.returnedFunc, this.Config.END_POINT);
    },
    insertScript: function(callback, endPoint) {
        var code = "api_key:" + this.Config.API_KEY + "\n" + 
                   "onLoad:" + callback + "\n" +
                   "authorize: true"
        var scriptElement = document.createElement('script');
        scriptElement.text = code;
        scriptElement.type = 'text/javascript';
        scriptElement.src = this.Config.END_POINT;

        document.body.appendChild(scriptElement);
    },
    returnedFunc: function() {
        console.log('callback', arguments);
    }

}

Linkedin.initalise();

})(jQuery, window);
Colin Brock
  • 21,267
  • 9
  • 46
  • 61
Owzzz
  • 177
  • 1
  • 4
  • 15

1 Answers1

1

To do this you need to authorize with OAuth. You blog can do this authorization (PHP/Perl/whatnot), but the clients cannot (JavaScript).

The reasons for this:

  • you are sharing the secret key, which can allow anyone access
  • you need to store state somewhere (the token). You should not store this on the client. You need a server in order to save the token.
Jonas G. Drange
  • 8,749
  • 2
  • 27
  • 38
  • Thanks Jonas, So in my callback I would start the OAuth journey? I can post to some PHP and handle it from there I suppose? I'd probably persist it within a cookie. – Owzzz Jul 29 '12 at 10:48
  • You could, but then why not move everything to PHP? :) If you have a database somewhere you can cache the linkedin info. I am sure linkedin has some sort of maximum limit of API calls. https://wordpress.org/extend/plugins/lips/ this plugin probably does some of the things you want to do. – Jonas G. Drange Jul 29 '12 at 10:52
  • Yes, I guess, I was just hoping I could handle most/all of it client side. But that's fine, I'll read up on the OAuth flow. Thanks – Owzzz Jul 29 '12 at 11:04
  • 1
    I tried to do client side authorization using githubs API. It works, but JavaScript just is not the right tool for the authorization part. Furthermore, the API has to support JSONP for you to access it cross-domain. Github's API does not and I have no reason to believe LinkedIn is any better. Good luck to you :) – Jonas G. Drange Jul 29 '12 at 11:12
  • @JonasG.Drange FYI, the LinkedIn API [does support JSONP](https://developer.linkedin.com/documents/api-requests-json) – Unpossible Jul 30 '12 at 02:34
  • Cool, but so did allegedly [Github](http://developer.github.com/v3/#json-p-callbacks). The github auth token though was not returned in proper JSON. Perhaps they have turned off client side auth? – Jonas G. Drange Jul 30 '12 at 06:49
  • Thanks guys, in my attempt to implement the oAuth journey in php I get this problem: http://stackoverflow.com/questions/11785141/cannot-get-oauth-php-extension-to-work – Owzzz Aug 02 '12 at 20:44