How I automate sharing content to Linkedin using Aylien’s content analysis API and Browsershot.

My goal here is to keep my Linkedin profile active in an automated way. The end result is that content related to PHP, which I have a lot of interest in, is posted to Linkedin, in to relevant Groups or on my Linkedin status page, often a few times a day, during the working hours.

Here is my Linkedin profile if you’d like to take a look at the automated posts, and to connect with m too of course! http://ie.linkedin.com/in/gordonmurray

The following is a small application I put together using PHP to gain experience in using Linkdin’s API¬†along with Browsershot to take screenshots of any URLs, as well as using Aylien’s API to extract some useful information such as a title, summary and some hash tags from a single webpage URL.

I have added the source code to Github if you wold like to implement this yourself : https://github.com/murrion/php_post_to_linkedin

The starting point is just a URL to a web page article I find interesting and want to share. The end result is a new ‘Share’ on my own Linkedin profile and/or a post to a Linkedin Group, with a prefilled Title, description, a small number of hash tags and a screenshot extracted from the original URL, all automatically.

If you want to replicate this process, you will need to create a Linkedin Application and sign up for an Aylien API key. Both are free to use.

The workflow of this application is the following:

  1. Look for any new links posted to the PHP subreddit at https://www.reddit.com/r/php
  2. Check to make sure it isn’t a link I have shared on Linkedin before by using a local log of links shared
  3. Generate a screenhot of the URL using Browsershot. (If the image is too small in byte size, it means that Browsershot didn’t work for some reason and instead a generic PHP image is used.
  4. Send the URL to Aylien, to see if their API can summarize the content of the page and also discover some potential hash tags.
  5. If the title of the URL it is sharing (determined from Aylien’s API) has PHP, Codeigniter or Laravel in their title, then post the content of one of those Groups on Linkedin that I am a member of. If one of those words isn’t in the title, just post it to my normal status page on Linkedin.
  6. Then, update the local list of links already shared.

Here is an image of the end result. This is an article shared to a Laravel group that I am a member of on Linkedin.

Screenshot from 2015-02-09 22:17:37

The Title, hash tags and brief description are all generated automatically by using Ayliens Article Extraction and Hashtag suggestion API calls.

Its worth mentioning that one of Aylien’s API endpoints is capable of extracting images from a URL source, but I found that it didn’t return an image every time and even if it did, it wasn’t necessarily relevant to the content of the page. Instead I opted for taking a screenshot of the target URL.

The screenshot image is generated using Browsershot, which uses PhantomJS to take a screenshot of the URL.

Aylien’s Hashtag suggestion tool is very very good. In one of my earlier attempts, I didn’t limit it in any way and it posted 24 Hash tags in a post. Nothing wrong with that, but I wanted to keep it short, so I limited my future versions to just 3 hash tags, as well as removing duplicates and avoiding hash tags with greater than 10 characters.

Screenshot from 2015-02-09 21:54:06

One of the more recent automatic posts to Linkedin, complete with a short number of hash tags, a title, some summary text and a screenshot of the site.

Screenshot from 2015-02-09 21:59:00

Useful links

Linkedin’s API documentation: https://developer.linkedin.com/apis
Ayliens API documentation: http://aylien.com/text-api-doc
Browsershot on Github : https://github.com/freekmurze/browsershot

Leave a Reply

Your email address will not be published. Required fields are marked *