Authenticate to linkedin

故事扮演 提交于 2019-12-12 04:07:34

问题


I am trying to write a code that get some user's linkedin profile and just print it

this is my code

from linkedin import linkedin

CONSUMER_KEY = "XXXXX"
CONSUMER_SECRET = "XXXXX"
RETURN_URL = r"http://localhost:8000"
authentication = linkedin.LinkedInAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
                                                  RETURN_URL, linkedin.PERMISSIONS.enums.values())

application = linkedin.LinkedInApplication(authentication)

a = application.get_profile(member_url=my_url)
print(a)

I get the following error

Traceback (most recent call last):
File "C:/Users/Linkedin/main.py", line 28, in <module>
a = application.get_profile(member_url=my_url)
File "C:\Python34\lib\site-packages\python_linkedin-4.2-py3.4.egg\linkedin\linkedin.py", line 189, in get_profile
response = self.make_request('GET', url, params=params, headers=headers)
File "C:\Python34\lib\site-packages\python_linkedin-4.2-py3.4.egg\linkedin\linkedin.py", line 169, in make_request
params.update({'oauth2_access_token': self.authentication.token.access_token})
   AttributeError: 'NoneType' object has no attribute 'access_token'

What do I do wrong?


回答1:


Not tested. Try this

As per the documentation. Access token must be generated to grand access to the application.

authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
application = linkedin.LinkedInApplication(token=authentication.get_access_token())

print authentication.authorization_url

When you grant access to the application, you will be redirected to the return url with the following query strings appended to your RETURN_URL:

"http://localhost:8000/?code=AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8&state=ea34a04b91c72863c82878d2b8f1836c"

Copy the code manually and set like

 authentication.authorization_code = 'AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8'

 authentication.get_access_token() #AQTFtPILQkJzXHrHtyQ0rjLe3W0I
 application = linkedin.LinkedInApplication(token='AQTFtPILQkJzXHrHtyQ0rjLe3W0I')


来源:https://stackoverflow.com/questions/36530946/authenticate-to-linkedin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!