ozgur / python-linkedin

Python interface to the LinkedIn API
http://ozgur.github.com/python-linkedin/
MIT License
889 stars 394 forks source link

cannot get access token #62

Open zhiyzuo opened 9 years ago

zhiyzuo commented 9 years ago

Maybe this is a dumb question but I'm totally new to apis and hope to get help.

I am following the instructions in the readme file and when I proceeded to

authentication.authorization_code = '???' authentication.get_access_token()

I got this error:

linkedin.exceptions.LinkedInError: invalid_request: missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired

I'm using http://localhost:8000 as the return_url. I pasted the link the python printed and got the authorization_code and use it in the above code but got the error.

Someone help me out please...Really have no idea...

baisk commented 9 years ago

me too! Does the return url really matters? Need I change the http://localhost:8000 to some www.XXX.com ? Help me!

cleder commented 9 years ago

afaik the return url really matters and it has to be registered in linkedIn api settings

baisk commented 9 years ago

I also registered https://localhost:8000 in linkedin api settings.

Now the problem is, I can only use the application for once. I forgot to remember the result of authentication.get_access_token(). I run the program again, input the authorization_code again, and got an error.

baisk commented 9 years ago

I guess the old authorization_code may still be valid, and it prevent another get_access_token() ?

cleder commented 9 years ago

Strange, I am pretty sure that you can request access tokens without limit. It would be impossible to log in from different devices/browsers at the same time with this being forbidden.

baisk commented 9 years ago

Could one user get two access tokens in the same time?

baisk commented 9 years ago
# -*- coding: utf-8 -*-
#!/usr/bin/env python
# @author: baisk <buaagaowei@gmail.com>
from linkedin import linkedin

# API_KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl'
# API_SECRET = 'daJDa6_8UcnGMw1yuq9TsjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG'

API_KEY = '75ikzf7tubpe8b'
API_SECRET = 'mG3ujuLsVfTEQukr'
RETURN_URL = 'https://localhost:8000'

# 注意这里的scope不能超过设置api时候的范围, 否则会超出权限而报错, 并且错误看不出来.
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL) #, linkedin.PERMISSIONS.enums.values())
print authentication.authorization_url  # open this url on your browser
application = linkedin.LinkedInApplication(authentication)

# https://localhost:8000/?code=AQRQglTv_nL6lGpYT1VuPKRVjgXoyMiibdDNYjzR_v9H9LM4EbdybziDgEbYfEJOOKOkq5vPU0G1g3WVN2djwS6pKnh5tjP6ky1aX_yraRqDpkS9C3g&state=fcb6805995568f449fb6eb4d7c358b22
authentication.authorization_code = 'AQRQglTv_nL6lGpYT1VuPKRVjgXoyMiibdDNYjzR_v9H9LM4EbdybziDgEbYfEJOOKOkq5vPU0G1g3WVN2djwS6pKnh5tjP6ky1aX_yraRqDpkS9C3g'
print authentication.get_access_token()

# print application.get_profile(selectors=['id', 'first-name', 'last-name', 'location', 'distance', 'num-connections', 'skills', 'educations'])
print application.get_profile()

# -*- end of file -*-
chfakht commented 5 years ago

I get "The redirect_uri does not match the registered value" when logging to authentication.authorization_url