Linkedin API:无法在 python 中使用 Linkedin API 获取访问令牌

Linkedin API: unable to get the access tokens using Linkedin API in python

我正在尝试使用 Linkedin API 检索访问令牌。我使用 python.

的 linkedin 包
from linkedin import linkedin

API_KEY = '*****'

API_SECRET = '******'

RETURN_URL = 'http://localhost:8080/hello' #(this works ok)


authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL)

print authentication.authorization_url  # open this url on your browser
application = linkedin.LinkedInApplication(authentication)

authentication.authorization_code = 'the code obtained from login in in previous link'

authentication.get_access_token()

我收到以下错误:

---------------------------------------------------------------------------
LinkedInError                             Traceback (most recent call last)
<ipython-input-26-a0063ada08a2> in <module>()
----> 1 authentication.get_access_token()

C:\Users\soledad.galli\AppData\Local\Continuum\Anaconda2\lib\site-packages\linkedin\linkedin.py in get_access_token(self, timeout)
113               'client_secret': self.secret}
114         response = requests.post(self.ACCESS_TOKEN_URL, data=qd, timeout=timeout, verify=False)
--> 115         raise_for_error(response)
116         response = response.json()
117         self.token = AccessToken(response['access_token'], response['expires_in'])

C:\Users\soledad.galli\AppData\Local\Continuum\Anaconda2\lib\site-packages\linkedin\utils.pyc in raise_for_error(response)
 61                 message = '%s: %s' % (response.get('error', error.message),
 62                                       response.get('error_description', 'Unknown Error'))
---> 63                 raise LinkedInError(message)
 64             else:
 65                 raise LinkedInError(error.message)


LinkedInError: invalid_request: missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : authorization code not found

我在其他地方读到过,这可能是因为访问令牌的寿命很短,但是,我设法快速复制和粘贴,但仍然遇到相同的错误。知道为什么或如何解决这个问题吗?

非常感谢

我遇到了同样的问题,证明我粘贴了错误的授权码。我觉得不能这么快过期是为了不能用,而是为了一拿到就可以用我改了代码才能贴上:

authentication.authorization_url  # open this url on your browser
print authentication.authorization_url
application = linkedin.LinkedInApplication(authentication)
code = raw_input("code = ")
authentication.authorization_code = code
print authentication.get_access_token()

在我的例子中,redirect_uri 在本地主机上,我在网络根目录中有一个 index.php,它打印出您需要粘贴到 python 脚本中的代码。 index.php 是这样的:

echo htmlspecialchars($_GET["code"]);

希望这对您有用。自己苦苦思索,终于找到了,其实并没有那么复杂。