Python を使用して LinkedIn Developer API にアクセスしようとしましたが、リンクされた API の呼び出し中に 401 エラーが発生しました。助けていただけませんか -
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
詳細なコードは次のとおりです-
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()