Python API';需要OAUTH_令牌和OAUTH_令牌密钥
如何从LinkedIn获取这些密钥Python API';需要OAUTH_令牌和OAUTH_令牌密钥,python,oauth-2.0,linkedin,data-science-studio,Python,Oauth 2.0,Linkedin,Data Science Studio,如何从LinkedIn获取这些密钥 OAUTH_TOKEN and OAUTH_TOKEN_SECRET 当我在LinkedIn Developer上注册我的应用程序时,我只得到: CONSUMER_KEY, CONSUMER_SECRET 我有两个Python函数需要它 例如: from linkedin import linkedin # pip install python-linkedin # Define CONSUMER_KEY, CONSUMER_SECRET, # U
OAUTH_TOKEN and OAUTH_TOKEN_SECRET
当我在LinkedIn Developer上注册我的应用程序时,我只得到:
CONSUMER_KEY, CONSUMER_SECRET
我有两个Python函数需要它
例如:
from linkedin import linkedin # pip install python-linkedin
# Define CONSUMER_KEY, CONSUMER_SECRET,
# USER_TOKEN, and USER_SECRET from the credentials
# provided in your LinkedIn application
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
USER_TOKEN = ''
USER_SECRET = ''
RETURN_URL = '' # Not required for developer authentication
# Instantiate the developer authentication class
auth = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
USER_TOKEN, USER_SECRET,
RETURN_URL,
permissions=linkedin.PERMISSIONS.enums.values())
# Pass it in to the app...
app = linkedin.LinkedInApplication(auth)
# Use the app...
app.get_profile()
及
#!/usr/bin/env python
#编码:utf-8
"""
linkedin-2-query.py
Created by Thomas Cabrol on 2012-12-03.
Copyright (c) 2012 dataiku. All rights reserved.
Building the LinkedIn Graph
import oauth2 as oauth
import urlparse
import simplejson
import codecs
CONSUMER_KEY = "your-consumer-key-here"
CONSUMER_SECRET = "your-consumer-secret-here"
OAUTH_TOKEN = "your-oauth-token-here"
OAUTH_TOKEN_SECRET = "your-oauth-token-secret-here"
OUTPUT = "linked.csv"
def linkedin_connections():
# Use your credentials to build the oauth client
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
token = oauth.Token(key=OAUTH_TOKEN, secret=OAUTH_TOKEN_SECRET)
client = oauth.Client(consumer, token)
# Fetch first degree connections
resp, content = client.request('http://api.linkedin.com/v1/people/~/connections?format=json')
results = simplejson.loads(content)
# File that will store the results
output = codecs.open(OUTPUT, 'w', 'utf-8')
# Loop thru the 1st degree connection and see how they connect to each other
for result in results["values"]:
con = "%s %s" % (result["firstName"].replace(",", " "), result["lastName"].replace(",", " "))
print >>output, "%s,%s" % ("Thomas Cabrol", con)
# This is the trick, use the search API to get related connections
u = "https://api.linkedin.com/v1/people/%s:(relation-to-viewer:(related-connections))?format=json" % result["id"]
resp, content = client.request(u)
rels = simplejson.loads(content)
try:
for rel in rels['relationToViewer']['relatedConnections']['values']:
sec = "%s %s" % (rel["firstName"].replace(",", " "), rel["lastName"].replace(",", " "))
print >>output, "%s,%s" % (con, sec)
except:
pass
if __name__ == '__main__':
linkedin_connections()
我从LinkedIn收到此文档:
这是否意味着API现在关闭了?LinkedIn仍然支持OAuth 1.0a,但它不再鼓励新的实现 作为身份验证工作流的一部分,您必须请求自己的OAuth 1.0a令牌/密钥值。为了方便起见,LinkedIn的应用程序管理控制台不再自动为您生成令牌/密钥值 切换到OAuth2.0可能是一种更简单的方法
此外,请注意,根据2月份LinkedIn开发者博客上发布的公告,您的图书馆为获取用户连接而拨打的电话已不再通过API公开。因此,使身份验证正常工作可能不是您遇到的唯一问题。我认为您正在使用OAuth 1.0身份验证,我不确定LinkedIn是否支持该身份验证。可能会切换到支持OAuth 2.0的客户端库。