2017-11-16 9 views
1

私はexperianのサンドボックスAPI(クレジット情報に関する情報を提供する)のoauthアクセストークンを生成しようとしています。 彼らtutorialは、アクセストークンを取得するには、この(偽のデータを)実行するように言う:PythonでOauthアクセストークンを取得

curl -X POST 
-d '{ "username":"[email protected]", "password":"YOURPASSWORD"}' 
-H "Client_id: 3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9" 
-H "Client_secret: ipu3WQDqTEjqZDXW" 
-H "Content-Type: application/json" 
"https://sandbox-us-api.experian.com/oauth2/v1/token" 

私はPythonでこれを実行するだろうか?私は他の多くのものの中で、これを試してみました:

data = { "username" : "[email protected]", "password":"YOURPASSWORD"} 

headers = {"Client_id": "3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9", "Client_secret": "ipu3WQDqTEjqZDXW", "Content-Type": "application/json"} 

response = requests.post("https://sandbox-us- 
api.experian.com/oauth2/v1/token", data=data, headers=headers) 

をすべてのヘルプは大幅にほとんど存在し

+0

は、あなたの質問に答えました。それが役に立ちましたら、答えを正しいとマークすることを検討してください:)へようこそ! – alexisdevarennes

+0

ありがとう!助けを感謝する – user123

答えて

0

をいただければ幸いです、ちょうど応答を解析する必要があります。

import json 

data = { "username" : "[email protected]", "password":"YOURPASSWORD"} 

headers = {"Client_id": "3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9", "Client_secret": "ipu3WQDqTEjqZDXW", "Content-Type": "application/json"} 

response = requests.post("https://sandbox-us-api.experian.com/oauth2/v1/token", data=data, headers=headers) 
if response.status_code in [200]: 
    tok_dict = json.loads(response.text) 
    print(tok_dict) 
    issued_at = tok_dict["issued_at"] 
    expires_in = tok_dict["expires_in"] 
    token_type = tok_dict["token_type"] 
    access_token = tok_dict["access_token"] 
else: 
    print(response.text) 
関連する問題