从Paypal请求交易清单

时间:2018-03-15 09:28:28

标签: java rest http paypal

我尝试从paypal请求交易列表,但我总是得到HTTP-Code 400

public void getTransactionList(String accessToken)
{
    try
    {
        URL url = new URL(
            "https://api.sandbox.paypal.com/v1/reporting/transactions"
                + "?start_date=2018-01-01T00:00:00Z&end_date=2018-04-01T00:00:00Z"
                + "&fields=all&page_size=100&page=1");

        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Authorization", "Bearer " + accessToken);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Accept-Language", "en_US");
        conn.setUseCaches(false);
        conn.setDoOutput(true);

        String line;
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

        while ((line = reader.readLine()) != null)
        {
            System.out.println(line);
        }
        reader.close();
    }
    catch (Throwable e)
    {
        e.printStackTrace();
        //throw new ActionException(e);
    }
}

例外是

java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.sandbox.paypal.com/v1/reporting/transactions?start_date=2018-01-01T00:00:00-000&end_date=2018-04-02T00:00:00-000&fields=all&page_size=100&page=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at de.crefo.workflow.paypal.http.HttpRestClient.getTransactionList(HttpRestClient.java:42)
at de.crefo.workflow.paypal.http.HttpRestClient.main(HttpRestClient.java:112)

Access-Token请求,我用类似的方式,工作得非常好,并给我一个有效的令牌。 我做错了什么?

EDIT。更改了URL中的dateformat,请参阅注释。

0 个答案:

没有答案