我是Python新手,我想测试linkedinapi。 我从这个站点得到了一个身份验证代码(使用oauth2)的示例:https://github.com/ozgur/python-linkedin
我想我的应用程序在Linkedin上的配置没有问题:
ID客户端:XXX
秘密客户端:YYY
所有这些复选框都选中了:r\u basicprofile、r\u emailaddress、rw_company峎admin、w峎u share
OAuth 2.0=>;授权URL:http://localhost:8000
代码如下:
#-*- coding: utf-8 -*-
from linkedin import linkedin
API_KEY = 'XXX'
API_SECRET = 'YYY'
RETURN_URL = 'http://localhost:8000'
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL)
print "authentication.authorization_url : " + authentication.authorization_url
print "authentication.key : " + authentication.key
print "authentication.secret : " + authentication.secret
print "authentication.redirect_uri : " + authentication.redirect_uri
print "authentication.state : " + authentication.state
print authentication.authorization_code
print authentication.token
print authentication._error
application = linkedin.LinkedInApplication(authentication)
结果是:
authentication.authorization_url : https://www.linkedin.com/uas/oauth2/authorization?scope=&state=a2eb48d9b7b5f94a24dfbf36d498ebdc&redirect_uri=http%3A//localho st%3A8000&response_type=code&client_id=XXX
authentication.key : XXX
authentication.secret : YYY
authentication.redirect_uri : http://localhost:8000
authentication.state : a2eb48d9b7b5f94a24dfbf36d498ebdc
None
None
None
我不明白为什么我的授权码是“无”。根据git-hub链接,重定向的url应该包含url+授权码。这里我只有网址,所以我不能继续认证过程。在
我做了些研究,但什么也没找到。有人知道我的代码或配置有什么问题吗?在
谢谢!在
好吧,我终于找到了问题所在!在
这将返回一个URL(例如:https://www.linkedin.com/uas/oauth2/authorization?scope=r_basicprofile%20r_emailaddress&state=4a8b5b5932f182fff0a1731ebfbb05ef&redirect_uri=http%3A//localhost%3A8000&response_type=code&client_id=XXX)。我必须在我的浏览器中打开这个网址,用我的Linkedin帐户登录。然后我被重定向到这个URL:http://localhost%3A8000/?code=my_code&state=31624da3ad7331c11def407de0a56cc4
my_code是用于获取令牌的代码。在
^{pr2}$一旦我得到令牌,我就可以请求使用API。在
希望这能有所帮助。在
相关问题 更多 >
编程相关推荐