问题描述
我试过很多方法,但没有一个似乎工作。帮我用python的LinkedIn的连接。我所有的令牌。我有蟒蛇2.7.5。请张贴基本code的样本用于建立连接,并得到一个用户名。
下面,我已经做字符字符像的例子中所述的,但它不工作
< ---这是我得到的API和我精确复制它。见下图:
CONSUMER_KEY ='9puxXXXXXXXX'#这是API_KEY
CONSUMER_SECRET ='brtXoXEXXXXXXXX'#这是SECRET_KEYUSER_TOKEN ='27138ae8-XXXXXXXXXXXXXXXXXXXXXXXXXXX'#这组oauth_token
USER_SECRET ='ca103e23XXXXXXXXXXXXXXXXXXXXXXXXXXX'#这是oauth_secret
从LinkedIn导入LinkedIn#定义CONSUMER_KEY,CONSUMER_SECRET,
#USER_TOKEN,并从凭证USER_SECRET
#在你的LinkedIn提供的应用#实例化开发类认证验证= linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY,CONSUMER_SECRET,
USER_TOKEN,USER_SECRET,
RETURN_URL,linkedin.PERMISSIONS.enums.values())#它传递到应用程序...应用= linkedin.LinkedInApplication(认证)#使用应用程序....application.get_profile()
我得到这个错误:
回溯(最后最近一次调用):
文件C:/ Documents和设置/ visolank /桌面/ Python的/程序/ linkedinapi.py,8号线,上述<&模块GT;
从LinkedIn导入LinkedIn
文件C:/ Documents和设置/ visolank /桌面/ Python的/程序\\ LinkedIn \\ linkedin.py,2号线,上述<&模块GT;
从requests_oauthlib进口您好!OAuth1
文件C:\\ Python27 \\ lib目录\\站点包\\ requests_oauthlib \\ __ init__.py,1号线,上述<&模块GT;
从进口。核心您好!OAuth1
文件C:\\ Python27 \\ lib目录\\站点包\\ requests_oauthlib \\ core.py,4号线,上述<&模块GT;
从oauthlib.oauth1进口(客户端,SIGNATURE_HMAC,SIGNATURE_TYPE_AUTH_HEADER)
文件C:\\ Python27 \\ lib目录\\站点包\\ requests_oauthlib \\ oauthlib \\您好!OAuth1 \\ __ init__.py,12号线,上述<&模块GT;
从.rfc5849进口客户端
文件C:\\ Python27 \\ lib目录\\站点包\\ requests_oauthlib \\ oauthlib \\您好!OAuth1 \\ rfc5849 \\ __ init__.py26行,上述<&模块GT;
从oauthlib.common导入请求,urlen code,generate_nonce
导入错误:没有模块名为oauthlib.common
明白了。对于未来的参考,你需要从这里下载oauthlib
这里是全功能code:
CONSUMER_KEY ='9pux1XcwXXXXXXXXXX'#这是API_KEY
CONSUMER_SECRET ='brtXoXEXXXXXXXXXXXXX'#这是SECRET_KEYUSER_TOKEN ='27138ae8-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXb'#这组oauth_token
USER_SECRET ='ca103e23-XXXXXXXXXXXXXXXXXXXXXXXX7bba512625e'#这是oauth_secret
RETURN_URL =的http://本地主机:8000'从LinkedIn导入LinkedIn
从oauthlib进口*#定义CONSUMER_KEY,CONSUMER_SECRET,
#USER_TOKEN,并从凭证USER_SECRET
#在你的LinkedIn提供的应用#实例化开发类认证验证= linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY,CONSUMER_SECRET,
USER_TOKEN,USER_SECRET,
RETURN_URL,linkedin.PERMISSIONS.enums.values())#它传递到应用程序...应用= linkedin.LinkedInApplication(认证)#使用应用程序....G = application.get_profile()
打印摹
I tried so many methods, but none seem to work. Help me make a connection with linkedin using python. I have all the tokens. I have python 2.7.5. Please post a sample of basic code that establishes a connection and gets a user's name.
Below, I have done character for character like the example said, but it doesn't work.
https://github.com/ozgur/python-linkedin <---This is where I got the api and I copied it exactly. See below:
CONSUMER_KEY = '9puxXXXXXXXX' # This is api_key
CONSUMER_SECRET = 'brtXoXEXXXXXXXX' # This is secret_key
USER_TOKEN = '27138ae8-XXXXXXXXXXXXXXXXXXXXXXXXXXX' # This is oauth_token
USER_SECRET = 'ca103e23XXXXXXXXXXXXXXXXXXXXXXXXXXX' # This is oauth_secret
from linkedin import linkedin
# Define CONSUMER_KEY, CONSUMER_SECRET,
# USER_TOKEN, and USER_SECRET from the credentials
# provided in your LinkedIn application
# Instantiate the developer authentication class
authentication = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
USER_TOKEN, USER_SECRET,
RETURN_URL, linkedin.PERMISSIONS.enums.values())
# Pass it in to the app...
application = linkedin.LinkedInApplication(authentication)
# Use the app....
application.get_profile()
I get this error:
Traceback (most recent call last):
File "C:/Documents and Settings/visolank/Desktop/Python/programs/linkedinapi.py", line 8, in <module>
from linkedin import linkedin
File "C:/Documents and Settings/visolank/Desktop/Python/programs\linkedin\linkedin.py", line 2, in <module>
from requests_oauthlib import OAuth1
File "C:\Python27\lib\site-packages\requests_oauthlib\__init__.py", line 1, in <module>
from .core import OAuth1
File "C:\Python27\lib\site-packages\requests_oauthlib\core.py", line 4, in <module>
from oauthlib.oauth1 import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER)
File "C:\Python27\lib\site-packages\requests_oauthlib\oauthlib\oauth1\__init__.py", line 12, in <module>
from .rfc5849 import Client
File "C:\Python27\lib\site-packages\requests_oauthlib\oauthlib\oauth1\rfc5849\__init__.py", line 26, in <module>
from oauthlib.common import Request, urlencode, generate_nonce
ImportError: No module named oauthlib.common
Got it. For future reference you need to download the oauthlib from here https://github.com/idan/oauthlib
here is the full functional code:
CONSUMER_KEY = '9pux1XcwXXXXXXXXXX' # This is api_key
CONSUMER_SECRET = 'brtXoXEXXXXXXXXXXXXX' # This is secret_key
USER_TOKEN = '27138ae8-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXb' # This is oauth_token
USER_SECRET = 'ca103e23-XXXXXXXXXXXXXXXXXXXXXXXX7bba512625e' # This is oauth_secret
RETURN_URL = 'http://localhost:8000'
from linkedin import linkedin
from oauthlib import *
# Define CONSUMER_KEY, CONSUMER_SECRET,
# USER_TOKEN, and USER_SECRET from the credentials
# provided in your LinkedIn application
# Instantiate the developer authentication class
authentication = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
USER_TOKEN, USER_SECRET,
RETURN_URL, linkedin.PERMISSIONS.enums.values())
# Pass it in to the app...
application = linkedin.LinkedInApplication(authentication)
# Use the app....
g = application.get_profile()
print g
这篇关于如何使用与Python API LinkedIn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!