【发布时间】:2014-10-25 03:53:35
【问题描述】:
我正在尝试通过 python 代码关注一些在 LinkedIn 上注册的公司,根据 LinkedIn API documentation 我需要使用 oauth2 - POST 方法来关注一家公司。
我的查询如下:
- 如何通过python代码指定特定公司名称来关注公司?
- 有人可以为此提供 python 代码吗?
我的代码如下:
oauth_token = oauth.Token(key=access_token_key, secret=access_token_secret)
oauth_consumer = oauth.Consumer(key=api_key, secret=api_secret)
signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()
http_method = "POST"
http_handler = urllib.HTTPHandler(debuglevel=_debug)
https_handler = urllib.HTTPSHandler(debuglevel=_debug)
def linkedinreq(url, method, parameters):
req = oauth.Request.from_consumer_and_token(oauth_consumer,
token=oauth_token,
http_method=http_method,
http_url=url,
parameters=parameters)
req.sign_request(signature_method_hmac_sha1, oauth_consumer, oauth_token)
req.to_postdata()
def fetchsamples():
url = "https://api.linkedin.com/v1/people/~/following/companies"
parameters = []
response = linkedinreq(url, "POST", parameters)
fetchsamples()
【问题讨论】: