paypal获取交易订单信息api(python实现)

  1. 获取access_token,需要ClientId和ClientSecret
  2. https://developer.paypal.com/docs/api/overview/#make-your-first-call curl -v https://api.sandbox.paypal.com/v1/oauth2/token \ -H "Accept: application/json" \ -H "Accept-Language: en_US" \ -u "client_id:secret" \ -d "grant_type=client_credentials"

    /v1/oauth2/token The get access token endpoint. client_id Your client ID. secret Your secret. grant_type The grant type. Set to client_credentials.

    返回:
    { "scope": "https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*", "nonce": "2017-06-08T18:30:28ZCl54Q_OlDqP6-4D03sDT8wRiHjKrYlb5EH7Di0gRrds", "access_token": "Access-Token", "token_type": "Bearer", "app_id": "APP-80W284485P519543T", "expires_in": 32398 }

    postman操作测试 1、Download the latest version of Postman for your environment, and open Postman. 2、Select the POST method. 3、Enter the https://api.sandbox.paypal.com/v1/oauth2/token request URL. 4、On the Authorization tab, select the Basic Auth type and enter this information:Username Your client ID. Password Your secret. 5、On the Body tab, select x-www-form-urlencoded and enter this information:key grant_type value client_credentials 6、Click Send.

    python sdk获取access_token方法:
    api = Api({ "mode": "live",# sandbox or live "client_id": client_id, "client_secret": client_secret}) access_token = api.get_access_token() print('access_token:' + access_token)


-------------------------------------------------------------------------------------------
2、通过tocken获取账单数据,返回账单和账单里的商品
接口地址:https://developer.paypal.com/docs/api/sync/v1/#transactions_get
url = 'https://api.paypal.com/v1/reporting/transactions?start_date=2018-12-16T00:00:00%2B0800&end_date=2018-12-30T00:00:00%2B0800&page_size=500&page=1&fields=all' headers = {"Authorization": "bearer " + access_token, 'Content-Type': 'application/json'} # headers = {"Authorization": "bearer "+ access_token['access_token'],'Content-Type': 'application/json'} # params = {'key1': 'value1', 'key2': ['value2', 'value3']} r = requests.get(url, headers=headers) with open('text.txt', 'w') as f: f.write(r.text)










【paypal获取交易订单信息api(python实现)】

    推荐阅读