LinkedIn Relations to Javascript Object

linkedinrelations.user.js - install as Greasemonkey User Script.

This Greasemonkey User Script is the basis for experiments with LinkedIn.com contact relations. It starts by spidering all "contacts" of the currently active account (you must be logged in). Then, all second order contacts (the contacts of your contacts) are retrieved.

The script puts a lime-colored button in the top right position of your LinkedIn My Contacts: Connections page. The button is labeled "Create JS Model".

Clicking this button starts the process. Depending on the number of your contacts and their contacts, this process may take some time. The current status is displayed in the button label "Spidering (# of threads)...".

Script output

After the process is completed, the button label reads "Done" and the result is wrapped up in a single Javascript Object Definition. This result is opened in a new Firefox Tab. The Javascript definition looks something like this:

/* JS Object file created with linkedinrelations.user.js */
// Thu Mar 30 2006 10:55:59 GMT+0200 (CEST)
gContacts = {
	596654: {
		"key": 596654,
		"name": "Johannes la Poutre",
		"email": "joe@example.com",
		"contacts": [10718, 1940, 1478, 308, 902, 8784, 10855, ...],
	},
	10718: {
		"key": 1022718,
		"name": "Jobs, Steve",
		"email": "steve@example.com",
		"contacts": [3702, 3415, 1797, 1817, 4881, 2284, ... ] },
...
};

Limitations and Warnings

Impact

This script can cause a heavy load on LinkedIn. All contact listings, and their contact listings are retrieved from the web server. This can be a substantial number of hits in a relative short time.
The script uses a "spider queue" with a maximum number of MAXREQ simultaneous page requests; feedback of the queue size is displayed during runtime.
Please do not over-use this script, more than one run in a couple of days doesn't make sense anyway. Do your experiments with the resulting javascript output instead!

Fragile

The script makes heavy use of "screen scraping". This means, using regular expressions to parse relevant data from html pages. This method is inherently fragile. All occurrences of these regular expressions and request URLs are marked with a comment: // pgtxt

Character encoding

LinkedIn uses ISO-Latin-1 as character encoding for their html pages. Apparently, GM expects UTF-8 only, so any diacritic characters will be garbled in the output. Currently, I see no way to fix this. See xmlhttprequest and character encoding/ for a work around.

Experiments

The Javascript object definition can be saved to a file and included in a regular HTML page for further scripting and experimenting.

<script type="text/javascript" src="li-object.js"></script>

This instantiates a global object, in variable gContacts, as per the sample snippet above.

Plotting relations

For this experiment, I generated output in dot file format. This file is used as input for Graphviz (I used the award winning version for Mac OS-X: graphviz 1.13 (v16)).

The result for my current 128 contacts, and their contacts, looks really complicated:

Graph of linkedin contact relations

In order to reduce the mess a little bit, I pruned all contacts with one or less contacts of their own. Contacts with more than a certain number of contacts are colored green / yellow / orange / red.

You can find the html page here: li2dot.html. Just feed it with your own Javascript links and you'll get a similar plot for your contacts!

Building a FOAF file

Still to do: generate a FOAF file. Maybe limit to the first order contacts only, as email addresses are missing from second order contacts.

Changelog

Version 1.00
    - initial release
    - this script is considered EXPERIMENTAL

Version 1.01
	- fix: email address extraction wasn't working OK
    - use http rather than https urls
      (Linkedin started redirecting those)
    - work around for character encoding issue
$Id: $

About Greasemonkey

Greasemonkey is a Firefox extension, which can change web pages by applying cleverly crafted user scripts after they are loaded in the browser.

Tip! Greasemonkey Hacks by Mark Pilgim.

More Greasemonkey User Scripts

For more, and a couple of Greasemonkey resources, see Greasemonkey User Scripts.