我正在尝试使用Sinch的Reporting API中的用户呼叫报告API (来自Voice REST API)。不幸的是,User Call给出了响应 报告API不正确(表示调用确实没有调用)。
具体来说,我正在访问网址:
https://reportingapi.sinch.com/v1/users/username/aaa/calls/data
用户名aaa。答复是:
{ “开始”: “2016-05-18T00:00:00”, “时间”:0, “成功”:0, “失败”:0}
今天是2016年6月17日。
此回复不正确。昨天,2016年6月16日,我做了几个 应用程序到应用程序调用(即,通过“数据”)使用用户aaa,因此使用用户aaa 响应应该表示非零“持续时间”和非零 “成功”。
请注意,在Sinch Dashboard中 - >报告 - >生成使用报告 CSV格式报告确实显示昨天用aaa做的调用 这样:
call ID here;user space ID here ;2016-06-16T17:21:05Z;ANSWER;HUNGUP;10;aaa;bbb;headers here;application key here
call ID here;user space ID here ;2016-06-16T17:22:08Z;ANSWER;HUNGUP;35;aaa;bbb;headers here;application key here
即午夜UTC和PDT已经通过了呼叫详细信息 记录(每天生成一次)表明确实是 电话已经发生。
你对这个问题有什么暗示吗?
我正在使用从此Sinch改编的代码访问用户呼叫报告API 教程:
https://www.sinch.com/tutorials/sign-requests-java/
稍加修改(例如,GET而不是POST, connection.setDoInput(true)而不是connection.setDoOutput(true), 等等)。如果它对任何事情有帮助,这是我的确切代码:
public static void send() {
try {
String key = "key here";
String secret = "secret here";
// timestamp
Date date= new java.util.Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String timestamp = dateFormat.format(date);
// other items
String httpVerb = "GET";
String path = "/v1/users/username/aaa/calls/data";
String contentType = "application/json";
String canonicalizedHeaders = "x-timestamp:" + timestamp;
String contentMd5 =""; // because it is a GET
// signing
String stringToSign = httpVerb + "\n" + contentMd5 + "\n" + contentType + "\n" + canonicalizedHeaders + "\n" + path;
String signature = signature(secret, stringToSign);
String authorization = "Application " + key + ":" + signature;
// make the call
URL url = new URL("https://reportingapi.sinch.com" + path/*+"?_start=2016-06-13&_stop=2016-07-10"*/);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setRequestProperty("content-type", "application/json");
connection.setRequestProperty("x-timestamp", timestamp);
connection.setRequestProperty("authorization", authorization);
StringBuilder response = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ( (line = br.readLine()) != null)
response.append(line);
br.close();
System.out.println(url);
System.out.println(response.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
private static String signature(String secret, String message) {
String signature = "";
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(Base64.decodeBase64(secret.getBytes()), "HmacSHA256");
sha256_HMAC.init(secret_key);
signature = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
} catch (Exception e){
System.out.println("Error");
}
return signature;
}
有人对此有任何建议吗?
谢谢!