Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linkedin 401 Error via python

Trying to access LinkedIn Developer API using Python but getting 401 error while invoking linkedin API. Could you please assist -

Traceback (most recent call last):
  File "user_request.py", line 33, in <module>
    print app.get_profile()
  File "/Users/bchawla/anaconda/lib/python2.7/site-packages/linkedin/linkedin.py", line 179, in get_profile
    raise_for_error(response)
  File "/Users/bchawla/anaconda/lib/python2.7/site-packages/linkedin/utils.py", line 63, in raise_for_error
    raise LinkedInError(message)
linkedin.exceptions.LinkedInError: 401 Client Error: Unauthorized for url: https://api.linkedin.com/v1/people/~: Unknown Error

The detailed code is as under -

import oauth2 as oauth
import urlparse
from linkedin import linkedin

consumer_key           = "{Key}"
consumer_secret        = "{Secret}"
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)

request_token_url      = 'https://api.linkedin.com/uas/oauth/requestToken'
resp, content = client.request(request_token_url, "POST")
if resp['status'] != '200':
    raise Exception("Invalid response %s." % resp['status'])

print content

request_token = dict(urlparse.parse_qsl(content))

print "    - oauth_token        = %s" % request_token['oauth_token']
print "    - oauth_token_secret = %s" % request_token['oauth_token_secret']


auth = linkedin.LinkedInDeveloperAuthentication(consumer_key, consumer_secret,
request_token['oauth_token'], request_token['oauth_token_secret'], '',
permissions=linkedin.PERMISSIONS.enums.values())

print linkedin.PERMISSIONS.enums.values()

app = linkedin.LinkedInApplication(auth)

print app.get_profile()
like image 644
B Chawla Avatar asked Jul 12 '26 11:07

B Chawla


1 Answers

The majority of the old linkedin APIs, including the people API that you are attempting to use, have been depreciated and restricted solely to pre-approved developers - you now need to be part of their development program (which is limited to a very small set of companies they actively work with).

See: https://developer-programs.linkedin.com/documents/people-search-api

People Search API is a part of our Vetted API Access Program. You must apply here and get LinkedIn's approval before using this API.

See also: https://developer.linkedin.com/blog/posts/2015/developer-program-changes

Starting on May 12, 2015, we will be limiting the open APIs to only support the following uses:

  • Allowing members to represent their professional identity via their LinkedIn profile using our Profile API.
  • Enabling members to post certifications directly to their LinkedIn profile with our Add to Profile tools.
  • Enabling members to share professional content to their LinkedIn network from across the Web leveraging our Share API.
  • Enabling companies to share professional content to LinkedIn with our Company API.

This is consistent with the error code that you are receiving - 401 - Unauthorized: Access is denied due to invalid credentials. - given you are not part their developer program, you do not have valid credentials to access it.

like image 143
kyrenia Avatar answered Jul 15 '26 00:07

kyrenia