简体   繁体   中英

Linkedin API Python

I'm trying to log-in to Linkedin. I created the App and extract the client_key and client_secret. Also I added http://localhost:8080/ as Redirect URLs. I have this error:

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()

The v1 APIs are no longer supported.
Applications requesting Version 1.0 APIs may experience issues as they are removing services. Hence, it is highly recommended to change it from v1 to v2 .
Link : https://engineering.linkedin.com/blog/2018/12/developer-program-updates
Try updating your code with the new set of APIs (currently v2), and it will work perfectly as you're expecting.
Link : https://pypi.org/project/python-linkedin-v2/

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM