Solicitud incorrecta de GDAX Java

Intentando solicitar datos privados en GDAX pero sigue recibiendo solicitudes incorrectas. No puedo entender lo que estoy haciendo mal. Por favor ayuda.

private static JsonObject getAuthenticatedData() {
        try {

            String accessSign = getAccess();
            System.setProperty("http.agent", "Java Client");

            URL url = new URL("https://api.gdax.com/accounts");
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("GET");

            con.setRequestProperty("CB-ACCESS-KEY", "accesskey");
            con.setRequestProperty("CB-ACCESS-SIGN", accessSign);
            con.setRequestProperty("CB-ACCESS-TIMESTAMP", ""+System.currentTimeMillis() / 1000L);
            con.setRequestProperty("CB-ACCESS-PASSPHRASE", "passphrase");
            con.setRequestProperty("Content-Type", "application/json");


            con.setConnectTimeout(5000);
            con.setReadTimeout(5000);

            String status = con.getResponseMessage();
            System.out.println(status);

            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer content = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            System.out.println(content);
            in.close();

            con.disconnect();

        }catch(Exception e) {
            e.printStackTrace();
        }
        return null;


    }

Y esto:

public static String getAccess() {

    //Set the Secret
    String secret = "secret==";
    //Build the PreHash
    String prehash = Instant.now().toEpochMilli()+"GET"+"/accounts";
    String hash = null;
    try {

        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
        sha256_HMAC.init(secret_key);

        hash = Base64.encodeBase64String(sha256_HMAC.doFinal(prehash.getBytes("UTF-8")));
         hash = hash.replace("\n", "");
        System.out.println(hash);
       }
       catch (Exception e){
           e.printStackTrace();
       }
    return hash;   
}
¿Qué tipo de errores obtienes? En su método getAccess(), String prehash, ¿no debería ser toEpochMilli() en segundos?
400 Petición Incorrecta
no importa lo que yo haga. siempre 400 mala solicitud sin otra descripción.

Respuestas (1)

¿Puede intentar agregar/modificar con las siguientes líneas de códigos en sus métodos:

JsonObject estático privado getAuthenticatedData() {

  Cadena marca de tiempo = Instant.now().getEpochSecond() + "";
  String accessSign = getAccess(timestamp);


  con.setRequestProperty("CB-ACCESS-TIMESTAMP", marca de tiempo);
  con.setRequestProperty("aceptar", "aplicación/json");
}
getAccess de cadena estática pública (marca de tiempo de cadena) {

  String prehash = marca de tiempo+"GET"+"/cuentas";
  byte[] secretDecoded = Base64.getDecoder().decode(secreto);
  SecretKeySpec secret_key = new SecretKeySpec(secretDecoded, "HmacSHA256");

  hash = Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(prehash.getBytes()));

  hash de retorno;
}