Category Archives: LinkedIn

Push news to LinkedIn Stream in your behalf

PrintBack in the past I promised a follow up article to explain how to push data to your LinkedIn stream. The time as come and here we go, so before we take off for this journey maybe you would like to create a LinkedIn fake account for your tests, instead of using your official one.

Just go the official page: https://www.linkedin.com and follow the usual steps for the account creation, once done continue with the tutorial.

In my case I don’t care too much about flooding my timeline since I get every now and then annoying spam mail and maybe that could be the right time to taste my revenge.

Jokes a part the core of this tutorial is represented by the developers API: https://www.linkedin.com/secure/developer. Those API permits you to interface your program to LinkedIn account and perform several actions for example, read/write your profile, share news on the social stream, share on your groups and basically communicate and access Job search.

Okay, more or less simple, let’s move ahead and click on the link, you will land in an almost empty page:

image

Just click on add new application and fill the form. If everything went well it will be prompted the following page:

image

Hurrah! Well done, that was the toughest part! Please take note (a screenshot) of those information since you will need them later during the hacking session.

Now the funniest part comes, in command line or in you preferred ruby editor create the ruby file, in my case I call it linkedin.rb. To consume the API we will use a gem called (guess what?) linkedin, so copy:

gem "linkedin"

To your gemfile (in the same directory as the linkedin.rb) and run bundle install in the command line. In case you do not have any gemfile just run gem install linkedin and it will install the gem for you.

Back to our code, first of all require the linkedin and json gems:

#!/usr/bin/env ruby
require 'linkedin' # gem install linkedin
require 'json'

Then setup a configuration hash map containing your keys and your tokens:

config = {
    your_consumer_key: '77ntor37ib7qbp',      #api key
    your_consumer_secret: 'HLFdYIBeA9TTglz3',  #secret key
    oauth_user_token: 'eeabc242-ff1c-474a-a6f2-eb519c967d09', #OAuth Token
    oauth_user_secret: '51ba5c4f-92ef-4e0f-bec0-ac0b1e2937c1' #OAuth Secret:
}

Instantiate and authorize the client:

client = LinkedIn::Client.new(
    config[:your_consumer_key],
    config[:your_consumer_secret]
)
 
client.authorize_from_access(
    config[:oauth_user_token],
    config[:oauth_user_secret]
)

And now the final step, define the data that you would like to share on your stream:

data={
    "comment"=>"Check out my article about LinkedIn Share API!",
    "content"=>{"title"=>"LinkedIn Developers API consumed via Ruby",
                "description"=>"Programmatically leverage the Share API to maximize engagement on user-generated content on LinkedIn",
                "submitted-url"=>"https://giovanni.degiorgi.me/2014/12/01/push-news-to-linkedin-stream-in-your-behalf/",
                "submitted-image-url"=>"https://giovanni.degiorgi.me/wp-content/uploads/2012/02/800x140xcropped-me.jpg.pagespeed.ic.QDRtxDC7uW.jpg"},
    "visibility"=> {"code"=> "anyone"}
}

Final step, use the client to share the data:

client.add_share(data)

Run the code and you will be able to find the news in you social stream:

image

As easy as drinking a glass of water, I hope you enjoyed the article, for any question or suggestions feel free to drop my a couple of lines.

I’ve just updated my professional profile on LinkedIn. Connect with me and view my profile.

LinkedIn Profile

Tagged , , , ,