嗨,我正在尝试使用 android studio 从 gdax 拨打休息 api 电话,我是休息电话的新手,所以我正在努力拨打这个电话
我相信这是 api 端点,
链接
它说 CB-ACCESS-KEY 标头是必需的
这是所有必需标题的列表
所有 REST 请求必须包含以下标头:
-CB-ACCESS-KEY 字符串形式的 api 密钥。
-CB-ACCESS-SIGN base64 编码的签名(请参阅签署消息)。
-CB-ACCESS-TIMESTAMP 请求的时间戳。
-CB-ACCESS-PASSPHRASE 创建 API 密钥时指定的密码。
-所有请求正文都应具有内容类型 application/json 并且是有效的 JSON。
链接到完整文档点击这里
这是我尝试使用但没有运气的代码
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);
}
}
我从我的 onCreate 调用这个任务
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new InfoTask().execute("accounts");
}
我不确定 CB-ACCESS-SIGN 使用什么参数,也不知道在哪里添加我的 api 密码,请帮忙