Sample Code – Authentication in Java

The following Java code illustrates how to calculate the “sig” parameter using query string authentication.

String myAppId = "ThisIsMyAppId";
String mySecret = "ThisIsMySecret";
String timestamp = Long.toString(System.currentTimeMillis());
 
StringBuilder buff = new StringBuilder();
buff.append(myAppId).append("\n");
buff.append("GET").append("\n");
buff.append(mySecret).append("\n");;
buff.append(timestamp).append("\n");
buff.append("/search/brands").append("\n");;
 
// BE SURE TO LOWER CASE!
String src = buff.toString().toLowerCase();
 
// Use Apache commons codec library to calculate MD5 hash.
// http://commons.apache.org/codec/.
// Libraries/functions should exist for other languages.
String sig = DigestUtils.md5Hex(src);

Leave a Comment/Question

Please leave these two fields as-is: