2012-02-23 18 views
1

hereの指示に従って、LinkedIn APIを使用してネットワーク外プロファイルにアクセスしようとしています。
私は自分のコードをPythonで書いています。「不正な」エラーを返すネットワーク外API呼び出しのリンク

私の理解では、私はちょうど私の名前はhttpsConnection要求に余分なヘッダを追加します。

通常の通話:

connection.request(method, relative_url, body = body, headers={'Authorization': OAuth_header})

ネットワーク外の呼び出し:

// these values were extracted from the http-header I received
name = x-li-auth-token
value = name:R8Y4
connection.request(method, relative_url, body = body, headers={'Authorization': OAuth_header, name: value})

ネットワークアウトコールを行うと、エラーが発生します。

error:
status: 401
timestamp: 1330027911625
request-id: VHUSL0J7TL
error-code: 0
message: [unauthorized]. OAU:k1tofeoqr4id|2dc38f4e-73d1-4d31-9330-dd82aca89616|*01|*01:1330027911:CRc7YYYQRe2VS6woJpGX+qYVa/Q=

私は自分のプロファイルと実際のネットワーク外のプロファイルの両方でこれをテストしていますが、エラーは変わりません。様々なAPIリクエストから
、やや「値」が変化し、私はすべてのバリエーションを試してみました:

"name:R8Y4"
"search-name:R8Y4"
"OUT_OF_NETWORK:R8Y4"

私はそれがHTTPヘッダに関係している推測しているが、私は何が間違っている見当がつかない。

助けてください!ありがとうございました。

答えて

3

私はあなたの呼び出しが失敗している理由はわかりません。ここでは、検証されたoauth2ライブラリをPythonで使用し、HTTPの会話全体を含むシーケンスを示します。プロファイル取得する http://api.linkedin.com/v1/people-search:(people:(distance,id,first-name,last-name,headline,api-standard-profile-request))

Parameters (I'm using OAuth in the parameters for this call) 
oauth_body_hash=2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D 
oauth_nonce=41358038 
oauth_timestamp=1330098205 
oauth_consumer_key=xxx 
oauth_signature_method=HMAC-SHA1 
facet=network%2CO 
oauth_version=1.0 
oauth_token=xxx 
keywords=Schneider+Electric 
oauth_signature=xxx 

Response includes: 
<person> 
    <distance>-1</distance> 
    <id>UBAQYFeiHo</id> 
    <first-name></first-name> 
    <last-name>Private</last-name> 
    <headline>Assistant Engineer at Schneider Electric</headline> 
    <api-standard-profile-request> 
    <url>http://api.linkedin.com/v1/people/UBAQYFeiHo</url> 
    <headers total="1"> 
     <http-header> 
     <name>x-li-auth-token</name> 
     <value>OUT_OF_NETWORK:wHti</value> 
     </http-header> 
    </headers> 
    </api-standard-profile-request> 
</person> 

第二コール、::

まず、検索を行う http://api.linkedin.com/v1/people/UBAQYFeiHo:(id,first-name,last-name)を

Request headers: 
Host: api.linkedin.com 
x-li-auth-token: OUT_OF_NETWORK:wHti 
accept-encoding: gzip, deflate 
user-agent: Python-httplib2/$Rev$ 

Response: 
{'status': '200', 'content-length': '158', 'content-location': u'http://api.linkedin.com/v1/people/UBAQYFeiHo:(id,first-name,last-name)?oauth_body_hash=2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D&oauth_nonce=27886786&oauth_timestamp=1330098212&oauth_consumer_key=xxx&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=xxx&oauth_signature=xxx', 'transfer-encoding': 'chunked', 'vary': '*', 'server': 'Apache-Coyote/1.1', '-content-encoding': 'gzip', 'date': 'Fri, 24 Feb 2012 15:43:34 GMT', 'x-li-request-id': 'N368G241EA', 'x-li-format': 'xml', 'content-type': 'text/xml;charset=UTF-8'} 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<person> 
    <id>UBAQYFeiHo</id> 
    <first-name></first-name> 
    <last-name>Private</last-name> 
</person> 

と第2パートの仕事を作るためのPythonコードoauth2ライブラリは

import oauth2 as oauth 
import time 

url = "http://api.linkedin.com/v1/people/UBAQYFeiHo:(id,first-name,last-name)" 
consumer = oauth.Consumer(
key="xxx", 
secret="xxx") 

token = oauth.Token(
key="xxx", 
secret="xxx") 

client = oauth.Client(consumer, token) 

resp, content = client.request(url, headers={'x-li-auth-token':'OUT_OF_NETWORK:wHti'}) 
print resp 
print content 
+0

ありがとうあなたもう一度キルステン:) – joulesm

+0

誰もがPython Oauth2ライブラリを使用! APIコールはシンプルで使いやすく理解しやすいです。 – joulesm

関連する問題