hi am trying to make a rest api call from gdax using android studio, am new to rest calls so i am struggling to make this call
i believe this is the api endpoint,
Link
it says CB-ACCESS-KEY header is required
here is a list of all the required headers
All REST requests must contain the following headers:
-CB-ACCESS-KEY The api key as a string.
-CB-ACCESS-SIGN The base64-encoded signature (see Signing a Message).
-CB-ACCESS-TIMESTAMP A timestamp for your request.
-CB-ACCESS-PASSPHRASE The passphrase you specified when creating the API key.
-All request bodies should have content type application/json and be valid JSON.
link to full document click here
here is the code i am trying to use with no luck
private class InfoTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... urls) {
System.out.println("oooooooooooooooooooook working2");
HttpURLConnection conn = null;
BufferedReader reader = null;
try{
String query = urls[0];
URL url = new URL(endpoint+query);
System.out.println(url);
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("CB-ACCESS-KEY", key);
// conn.setRequestProperty("CB-ACCESS-SIGN", generate(params[0], "GET", "", String.valueOf(System.currentTimeMillis())));
String timestamp = String.valueOf(System.currentTimeMillis());
conn.setRequestProperty("CB-ACCESS-TIMESTAMP", timestamp);
conn.setRequestProperty("CB-ACCESS-PASSPHRASE", passprase);
Writer writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(query);
writer.flush();
writer.close();
conn.connect();
InputStream is = conn.getInputStream();
reader = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
String line = "";
while((line = reader.readLine()) != null){
sb.append(line);
}
return sb.toString();
}catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result){
TextView t = findViewById(R.id.t);
t.setText(result);
}
}
i am calling this task from my onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new InfoTask().execute("accounts");
}
i am not sure what parameters to use for the CB-ACCESS-SIGN and also don't know where to add my api secret please help