提问者:小点点

为什么当我试图获得我过去的贝宝交易时会得到这个错误?


我正在试着阅读我过去的交易记录。 我已经用curl工具做了这件事,但是我不能让它在NodeJS中工作。 我正在用请求API尝试这一点。 从paypal获得代币就很好用了。 只是不知道该怎么做

curl -v -X GET https://api.paypal.com/v1/reporting/transactions?start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer access-token"

目前在NodeJS中我有这个。 有人能帮我弄清楚吗?

var request = require('request');

let token;

request.post({
    uri: "https://api.paypal.com/v1/oauth2/token",
    headers: {
        "Accept": "application/json",
        "Accept-Language": "en_US",
        "content-type": "application/x-www-form-urlencoded"
    },
    auth: {
        'user': client_id,
        'pass': secret,
    },
    form: {
        "grant_type": "client_credentials"
    }
}, function (error, response, body) {
    let resp = JSON.parse(body);
    token = resp.access_token;
    console.log(token)
    if (error)
        console.log(error)

    getTransactions();
});


function getTransactions() {
    if (!token) {
        console.error("Could not get token");
        return;
    }


    request.post({
        uri: "https://api.paypal.com/v1/reporting/transactions?start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00",
        headers: {
            "content-type": "application/json"
        },
        auth: {
            bearer: token,
        }
    }, function (error, response, body) {
        console.log(body);
        console.log(error)
        console.log(JSON.stringify(response))

    });
}

错误:

"statusCode":404,"body":"","headers":{"content-length":"0",
"connection":"close","date":"Sun, 21 Jun 2020 00:35:15 GMT",
"cache-control":"max-age=0, no-cache, no-store, must-revalidate",
"paypal-debug-id":"207f5d4c9341",
"strict-transport-security":"max-age=31536000; includeSubDomains"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,
"host":"api.paypal.com","port":443,"hostname":"api.paypal.com",
"hash":null,
"search":"?start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00",
"query":"start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00",
"pathname":"/v1/reporting/transactions",
"path":"/v1/reporting/transactions?start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00",
"href":"https://api.paypal.com/v1/reporting/transactions?start_date=2020-05-20T01:01:01-00:00&end_date=2020-06-19T01:01:01-00:00"},
"method":"POST","headers":{"Accept":"application/json",
"Accept-Language":"en_US","content-type":"application/x-www-form-urlencoded",
"authorization":"Bearer accesstoken_is_my_little_secret",
"content-length":0}}}
        index.js:38

共1个答案

匿名用户

您的NodeJS发送的是POST请求而不是GET,因此404

相关问题