Linkedin API Python

2024-03-29 10:37:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试登录Linkedin。我创建了这个应用程序并提取了客户端密钥和客户端密钥。我还添加了http://localhost:8080/作为重定向URL。 我有个错误:

linkedin.exceptions.LinkedInError: 410 Client Error: Gone for url: https://api.linkedin.com/v1/people/~: This resource is no longer available under v1 APIs

# pip install python-linkedin
from linkedin import linkedin
import oauth2 as oauth
import urllib

consumer_key = ''
consumer_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'])
content_utf8 = str(content, 'utf-8')
request_token = dict(urllib.parse.parse_qsl(content_utf8))
authorize_url = request_token['xoauth_request_auth_url']

print('Go to the following link in your browser:', "\n")
print(authorize_url + '?oauth_token=' + request_token['oauth_token'])

accepted = 'n'
while accepted.lower() == 'n':
    accepted = input('Have you authorized me? (y/n)')
oauth_verifier = input('What is the PIN?')

access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'
token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
resp, content = client.request(access_token_url, 'POST')
content8 = str(content, 'utf-8')
access_token = dict(urllib.parse.parse_qsl(content8))
USER_TOKEN = access_token['oauth_token']
USER_SECRET = access_token['oauth_token_secret']
RETURN_URL = 'http://localhost:8080'

authentication = linkedin.LinkedInDeveloperAuthentication(
    consumer_key,
    consumer_secret,
    USER_TOKEN,
    USER_SECRET,
    RETURN_URL,
    linkedin.PERMISSIONS.enums.values()
)
application = linkedin.LinkedInApplication(authentication)
application.get_profile()

Tags: clienttokenurlsecretaccessconsumerparserequest