Mercadopago curl请求生成测试用户

时间:2018-08-22 14:47:10

标签: api curl request

需要进行此API调用才能创建测试用户

# Get access token
AT=`curl -s -X POST -H 'content-type: application/x-www-form-urlencoded' 'https://api.mercadopago.com/oauth/token' -d 'grant_type=client_credentials' -d 'client_id=CLIENT_ID' -d 'client_secret=CLIENT_SECRET' | grep -o '"access_token":"[^"]*"' | sed -n 's/.*"access_token":"\(.*\)"/\1/p'`

curl -X POST \
-H "Content-Type: application/json" \
"https://api.mercadopago.com/users/test_user?access_token=$AT" \
-d '{"site_id":"SITE_ID"}'

我使用在线服务将其解析为python请求并获得了

import requests

headers = {
    'content-type': 'application/x-www-form-urlencoded',
    'Content-Type': 'application/json',
}

data = [
  ('grant_type', 'client_credentials'),
  ('client_id', 'CLIENT_ID'),
  ('client_secret', 'CLIENT_SECRET'),
  ('{"site_id":"SITE_ID"}', ''),
]

response = requests.post('https://api.mercadopago.com/oauth/token', headers=headers, data=data)

但是它返回错误400。

0 个答案:

没有答案