我想使用apple new publisher API访问我的频道。我试图在apple documentation
中复制相同的pythonString finalUrl = baseURL + channelId;
String date= getCurrentDate();
String canonical_request = "GET"+finalUrl + date;
String authHeader = "HHMAC;key="+apiKeyId+";signature="+getSignature(secret, canonical_request)+";date="+date;
CloseableHttpClient client = HttpClients.custom().build();
HttpUriRequest request = RequestBuilder.get()
.setUri(finalUrl)
.setHeader(HttpHeaders.AUTHORIZATION, authHeader)
.build();
CloseableHttpResponse response = client.execute(request);
我如何获得签名:
private static String getSignature(String secret, String data) {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
return Base64.encodeBase64String(sha256_HMAC.doFinal(data.getBytes()));
}
我总是得到401. python代码正在运行。我试图从python代码中复制错误,它只在我没有设置授权标题时发生,而不是在签名错误时(也是根据apple news publisher API documentation),这意味着标题是没有设置。您可以查看整个请求here