401 Unauthorized Response from Apple New Publisher API

251 views Asked by At

I want to access my channel with the apple new publisher API. I am trying to replicate the same python in the apple documentation

String 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);  

How I get the signature:

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()));  
}

I am always getting 401. The python code is working. I tried to replicate the error from the python code and it happens only when I don't set the authorization header and not when the signature is wrong (also according to apple news publisher API documentation) which means somehow the header is not set. You can check the whole request here

0

There are 0 answers