author: | Thava Alagu thavamuni@gmail.com |
---|---|
Version: | 0.8 |
Date: | 2016 October 07 |
status: | Draft |
Register Your Application: https://www.linkedin.com/secure/developer
LinkedIn uses the OAuth 1.0a protocol
Get your oauth keys
Access your own profile. See Accessing Self Profile
Applications can sign-in on behalf of users – For that you need to use OAuth 1.0a protocol. Fine granular permission can be granted by your users to the application.
you can configure your application as to how the user should be redirected on successful authentication.
See http://oauth.net/code/ for example oauth code in all languages.
There is a walkthrough on using oauth plugin with PHP here: http://toys.lerdorf.com/archives/50-Using-pecloauth-to-post-to-Twitter.html
See Oauth Steps for exact steps.
Linked in does not seem to have API for accept-invitation. See Linkedin-Permissions
See API Notes
Here is how in PHP:
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("abcd123456", "efgh987654"); // apikey, secretkey
$oauth->setToken("abcd1234-efgh987-9988", "9876abcd-123asdf-1122");
// user-token, user-secret
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "http://api.linkedin.com/v1/people/~";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "http://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
echo $oauth->getLastResponse();
Here is what you get in JSON:
{
"firstName": "Kamyar",
"headline": "Senior Partner Engineer at LinkedIn",
"lastName": "Mohager",
"siteStandardProfileRequest": {
"url": "http://www.linkedin.com/profile?viewProfile=&key=8219502&authToken=SqI1&authType=name&trk=api*a108281*s116823*"
}
}
Do json_decode to convert:
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true)); /* true for associative array result */
?>
array(5) {
["a"] => int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
Authorize the application. The end result is you get the request_token
import oauth2 as oauth
import urlparse
consumer_key = "XXXXXXXXXXX"
consumer_secret = "XXXXXXXXXXX"
request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken' // <=== POST
access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'
authorize_url = 'https://www.linkedin.com/uas/oauth/authenticate'
consumer = oauth.Consumer(consumer_key, consumer_secret)
resp, content = client.request(request_token_url, "POST")
request_token = dict(urlparse.parse_qsl(content))