2014-08-31 79 views
0

我正在尝试关注一些通过Python代码在LinkedIn上注册的公司,并按照LinkedIn API documentation我需要使用oauth2 - POST方法来关注公司。Python - oauth2 - linkedin API

我的查询低于:

  1. 如何通过Python代码指定要遵循公司的一个公司的名称?
  2. 有人可以建议这个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() 

回答

1

而是另起炉灶的,使用python-linkedin包装。

示例代码以搜索公司:

from linkedin import linkedin 

CONSUMER_KEY = 'your key' 
CONSUMER_SECRET = 'your secret' 
USER_TOKEN = 'your token' 
USER_SECRET = 'your user secret' 
RETURN_URL = '' 

# 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) 

print application.search_company(selectors=[{'companies': ['name', 'universal-name', 'website-url']}], 
           params={'keywords': 'apple microsoft'}) 

要遵循公司,使用follow_company()方法,看到更多信息和示例here

COMPANY_ID = 1035 # this you would get from the `search_company()` 
application.follow_company(COMPANY_ID) 
+0

感谢您的答复。我遇到了这个链接并使用它。但是,我想知道关于oauth2中的POST。我无法找到理解这一点的好教程。 – Chandra 2014-09-01 01:54:36