Unable to add new Target on CRS

0 votes
asked Mar 3, 2018 by surender (210 points)
I have a basic sdk license and 14 day trial on CRS NA.

So I have three keys:

app-key:A

cloud-key:B

cloud-secret:C

I am using the POST method for application/json and sending appKey as B but I always get this response:

                                                                           { "statusCode" : 1,
                                                                             "result" : {
                                                                               "message" : "invalid app key"
                                                                             },
                                                                             "date" : "2018-03-03T14:06:03.031Z"
                                                                           }

I have created signature as required using cloud secret C and appKey B. On sending an empty picture, i get buffer empty as the message.

Please help if you can create new targets on crs.

1 Answer

+1 vote
answered Mar 3, 2018 by surender (210 points)
 
Best answer

Okay, I got this working. Let me leave a procedure for anyone struggling with the documentation:

First of all the two keys needed are cloud-key and cloud-secret.

You need date in this format:

"yyyy-MM-dd'T'HH:mm:ss.xxxZ" called the ISO-8601 date string. (For Android)
String formattedDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.530Z").format(new Date());
Now you need to create a string like this:(I am using Android in java)
String signing = "active1appKey"+getString(R.string.cloud_key)+"date"+formattedDate+"image"+encodedString+"meta"+videoUrl+"name"+targetName+"size20typeImageTarget"+getString(R.string.cloud_secret);
For image's encoded String(where mCurrentPhotoPath is AbsolutePath in string format):
String encodedString= null;
try {
    encodedString = Base64.getEncoder().encodeToString(
            Files.readAllBytes(Paths.get(mCurrentPhotoPath)));
} catch (IOException e) {
    e.printStackTrace();
}
Next you need to sha1 hash it:
String hashCode= new String(Hex.encodeHex(DigestUtils.sha1(signing)));
Next construct a jsonObject:
JSONObject params = new JSONObject();
try {
    params.put("image",encodedString );
    params.put("active", "1");
    params.put("name",targetName);
    params.put("size","20");
    params.put("meta",videoUrl);
    params.put("type","ImageTarget");
    params.put("date",formattedDate);
    params.put("appKey",getString(R.string.cloud_key));
    params.put("signature",hashCode);
} catch ( JSONException e) {
    e.printStackTrace();
}
Next have params.toString() and you will get the jsonString.
Then just use this in the body and make a POST request to the cloud server url ending in port 8888.
Edit:
You can use these resources for understanding better, they are from EasyAR but are not listed on the site and have java, go examples:
https://github.com/EasyAR/irsamples
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...