Update number 2.
Little progress, but still not working webhook registration. My problem was that my API was secured and all calls from Twitter API were unauthorized. Now the problem is with CRC token value or json format.
Sample responses from my service:
{
"response_token": "sha256=ojxyskCc4wQJgYcsxnt+9oaR38Q="
}
{
"response_token": "sha256=tsXrbLNRJ/u36/2dniuiP5ZyiGg="
}
And response body for twurl /1.1/account_activity/webhooks.json -d ‘url=<BASE_URI>/twitter/webhook’ -t
{
"errors":[
{
"code":214,
"message":"Webhook URL does not meet the requirements. Invalid CRC token or json response format."
}
]
}
To calculate response_token I use same algorithm as for creating signature during authorizing requests.
This is code used to calculate response_token:
public String encode(String source, String consumerSecret) {
try {
byte[] keyBytes = consumerSecret.getBytes();
SecretKey secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
final byte[] text = source.getBytes();
return new String(Base64.encodeBase64(mac.doFinal(text))).trim();
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException("Could not encode");
}
}