iink SDK Web

Answered

Error message —— {"code":"access.not.granted","message":"Access not granted"}

The correct applicationKey and hmac are entered。But still an error    "Access not granted"。


curl -X POST "https://cloud.myscript.com/api/v4.0/iink/batch" -H "accept: */*" -H "applicationKey: ******" -H "hmac: ******" -H "Accept: List [ "application/vnd.myscript.jiix", "application/json" ]" -H "Content-Type: application/json" -d "{ \"configuration\": { \"alwaysConnected\": true, \"diagram\": { \"convert\": { \"edge\": true, \"node\": true, \"text\": true }, \"enable-sub-blocks\": true, \"text\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } }, \"export\": { \"image-resolution\": 300, \"jiix\": { \"bounding-box\": false, \"strokes\": true, \"style\": false, \"text\": { \"chars\": false, \"words\": true } } }, \"lang\": \"en_US\", \"math\": { \"customGrammarContent\": \"symbol = 0\\\expression ::= identity(symbol)\\\start(expression)\", \"customGrammarId\": \"your_custom_grammar_id\", \"margin\": { \"bottom\": 10, \"left\": 15, \"right\": 15, \"top\": 10 }, \"solver\": { \"angle-unit\": \"deg\", \"decimal-separator\": \".\", \"enable\": true, \"fraction-mode\": \"decimal\", \"fractional-part-digits\": 3, \"options\": \"algebraic\", \"rounding-mode\": \"half up\" } }, \"raw-content\": { \"recognition\": { \"shape\": true, \"text\": true }, \"text\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } }, \"text\": { \"configuration\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] }, \"guides\": { \"enable\": true }, \"margin\": { \"bottom\": 10, \"left\": 15, \"right\": 15, \"top\": 10 } } }, \"contentType\": \"Text\", \"conversionState\": \"DIGITAL_EDIT\", \"height\": 620, \"strokeGroups\": [ { \"penStyle\": \"color: #120f51;↵-myscript-pen-width: 2;\", \"penStyleClasses\": \"ink mycolor\", \"strokes\": [ { \"id\": \"string\", \"p\": [ 0.5, 0.8221720589961077, 0.7145158745241171, 0.6761535882018319, 0.6761535882018319, 0.6761535882018319, 0.7145158745241171, 0.6831899108492184, 0.7145158745241171, 0.6831899108492184, 0.6831899108492184 ], \"pointerId\": 0, \"pointerType\": \"PEN\", \"t\": [ 1516717383637, 1516717383677, 1516717383694, 1516717383711, 1516717383727, 1516717383744, 1516717383761, 1516717383777, 1516717383794, 1516717383811, 1516717383827 ], \"x\": [ 289, 290, 290, 290, 290, 290, 290, 291, 291, 292, 293 ], \"y\": [ 215, 218, 222, 225, 228, 231, 235, 238, 242, 245, 248 ] } ] } ], \"theme\": \"ink {color: #000000; -myscript-pen-width: 1; -myscript-pen-fill-style: none; -myscript-pen-fill-color: #FFFFFF00;} mycolor {color: #120f51;} .math { font-family: STIXGeneral;} .math-solved {font-family: STIXGeneral; color: #A8A8A8FF;} .text {font-family: Open Sans; font-size: 10;}\", \"width\": 722, \"xDPI\": 96, \"yDPI\": 96}"


Best Answer

Dear 天美意 深圳,


currently, we are questionning about your request. What are you trying to recognize: text, math, diagram, raw-content? Indeed, in your request, you set all the modes, while only one should be set.


In the same way, why are you adding "customLexicon", "customResources" and "customGrammarContent" fields: "customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } ? These are not necessary fr a "first request"?


All this lead to a badly formed request.


For information, you can refer to the following samples, that show how you can use our REST API:

For TEXT:

-https://github.com/MyScript/myscript-text-web/blob/master/src/demo-app/examples/v4/iink_rest.html

-https://myscript.github.io/myscript-text-web/#/elements/myscript-text-web/demos/other-examples (for the latter, the source code is nto available, this should be fixed shortly)

for Math:

-https://github.com/MyScript/myscript-math-web/blob/master/src/demo-app/examples/v4/iink_rest.html

-https://myscript.github.io/myscript-math-web/#/elements/myscript-math-web/demos/other-examples


Reworking your request considering you just want to recognize text, it worked properly.


Please find it below.


Best regards,


Oliver


curl -X POST \

  https://cloud.myscript.com/api/v4.0/iink/batch \

  -H 'Accept: application/vnd.myscript.jiix,application/json' \

  -H 'Content-Type: application/json' \

  -H 'applicationKey: xxx' \

  -H 'hmackey: xxx' \

  -d '{

  "configuration": {

    "export": {

      "image-resolution": 300,

      "jiix": {

        "bounding-box": false,

        "strokes": true,

        "style": false,

        "text": {

          "chars": false,

          "words": true

        }

      }

    },

    "lang": "en_US"

  },

  "contentType": "Text",

  "conversionState": "DIGITAL_EDIT",

  "height": 620,

  "strokeGroups": [

    {

      "penStyle": "color: #120f51;↵-myscript-pen-width: 2;",

      "penStyleClasses": "ink mycolor",

      "strokes": [

        {

          "id": "string",

          "p": [

            0.5,

            0.8221720589961077,

            0.7145158745241171,

            0.6761535882018319,

            0.6761535882018319,

            0.6761535882018319,

            0.7145158745241171,

            0.6831899108492184,

            0.7145158745241171,

            0.6831899108492184,

            0.6831899108492184

          ],

          "pointerId": 0,

          "pointerType": "PEN",

          "t": [

            1516717383637,

            1516717383677,

            1516717383694,

            1516717383711,

            1516717383727,

            1516717383744,

            1516717383761,

            1516717383777,

            1516717383794,

            1516717383811,

            1516717383827

          ],

          "x": [

            289,

            290,

            290,

            290,

            290,

            290,

            290,

            291,

            291,

            292,

            293

          ],

          "y": [

            215,

            218,

            222,

            225,

            228,

            231,

            235,

            238,

            242,

            245,

            248

          ]

        }

      ]

    }

  ],

  "theme": "ink {color: #000000; -myscript-pen-width: 1; -myscript-pen-fill-style: none; -myscript-pen-fill-color: #FFFFFF00;} mycolor {color: #120f51;} .math { font-family: STIXGeneral;} .math-solved {font-family: STIXGeneral; color: #A8A8A8FF;} .text {font-family: Open Sans; font-size: 10;}",

  "width": 722,

  "xDPI": 96,

  "yDPI": 96

}

'


Dear 天美意 深圳,


We have tested it in the MyScript Cloud administration interface and it seems working fine.


Can you please ensure you send the right hmackey.

In the REST mode, you need to compute the input sent to the server : https://developer.myscript.com/support/account/registering-myscript-cloud/#computing-the-hmac-value


Regards,


Maël

Calculate hmackey based on the code you provided,Is there a problem?

hmackey calculation java code:


import javax.crypto.Mac;

import javax.crypto.spec.SecretKeySpec;

public class HmacsUtil {

  /**

     * Used to build output as Hex

     */

    private static final char[] DIGITS_LOWER =

        {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

  protected static char[] encodeHex(final byte[] data, final char[] toDigits) {

         final int l = data.length;

         final char[] out = new char[l << 1];

         // two characters form the hex value.

         for (int i = 0, j = 0; i < l; i++) {

             out[j++] = toDigits[(0xF0 & data[i]) >>> 4];

             out[j++] = toDigits[0x0F & data[i]];

         }

         return out;

  }

 static String computeHMAC(String applicationKey, String hmacKey, String jsonInput) {

    final String HMAC_SHA_512_ALGORITHM = "HmacSHA512";

    final String userKey = applicationKey + hmacKey;

    try {

      // get an hmac_sha512 key from the raw key bytes

      SecretKeySpec signingKey = new SecretKeySpec(userKey.getBytes(), HMAC_SHA_512_ALGORITHM);

      // get an hmac_sha512 Mac instance and initialize with the signing key

      Mac mac = Mac.getInstance(HMAC_SHA_512_ALGORITHM);

      mac.init(signingKey);

      // compute the hmac on input data bytes

      byte[] rawHmac = mac.doFinal(jsonInput.getBytes());

      return new String(encodeHex(rawHmac, DIGITS_LOWER ));

        //Hex.encodeHexString(rawHmac);

    } catch (Exception e) {

      throw new RuntimeException(e);

    }

  }

 public static void main(String [] args) {

  String applicationKey="******";

  String hmacKey="******";

  String jsonInput="\"strokeGroups\":[{\"penStyle\":\"color: #120f51;↵-myscript-pen-width: 2;\",\"penStyleClasses\":\"ink mycolor\",\"strokes\":[{\"id\":\"string\",\"p\":[0.5,0.8221720589961077,0.7145158745241171,0.6761535882018319,0.6761535882018319,0.6761535882018319,0.7145158745241171,0.6831899108492184,0.7145158745241171,0.6831899108492184,0.6831899108492184],\"pointerId\":0,\"pointerType\":\"PEN\",\"t\":[1516717383637,1516717383677,1516717383694,1516717383711,1516717383727,1516717383744,1516717383761,1516717383777,1516717383794,1516717383811,1516717383827],\"x\":[289,290,290,290,290,290,290,291,291,292,293],\"y\":[215,218,222,225,228,231,235,238,242,245,248]}]}]";

  String hmac=computeHMAC( applicationKey, hmacKey, jsonInput);

  System.out.println(hmac);

 }

}

Dear 天美意 深圳,,


Can you please save your full request before it is posted, and provide it?


Indeed, I tried again on my side, and apart from a badly computed hmac key, I do not see any other issue.


Best regards,


Olivier

full reques:

curl -X POST "https://cloud.myscript.com/api/v4.0/iink/batch" -H "accept: */*" -H "applicationKey: xxx" -H "hmac: xxx" -H "Accept: List [ "application/vnd.myscript.jiix", "application/json" ]" -H "Content-Type: application/json" -d "{ \"configuration\": { \"alwaysConnected\": true, \"diagram\": { \"convert\": { \"edge\": true, \"node\": true, \"text\": true }, \"enable-sub-blocks\": true, \"text\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } }, \"export\": { \"image-resolution\": 300, \"jiix\": { \"bounding-box\": false, \"strokes\": true, \"style\": false, \"text\": { \"chars\": false, \"words\": true } } }, \"lang\": \"en_US\", \"math\": { \"customGrammarContent\": \"symbol = 0\\\expression ::= identity(symbol)\\\start(expression)\", \"customGrammarId\": \"your_custom_grammar_id\", \"margin\": { \"bottom\": 10, \"left\": 15, \"right\": 15, \"top\": 10 }, \"solver\": { \"angle-unit\": \"deg\", \"decimal-separator\": \".\", \"enable\": true, \"fraction-mode\": \"decimal\", \"fractional-part-digits\": 3, \"options\": \"algebraic\", \"rounding-mode\": \"half up\" } }, \"raw-content\": { \"recognition\": { \"shape\": true, \"text\": true }, \"text\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } }, \"text\": { \"configuration\": { \"addLKText\": true, \"customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] }, \"guides\": { \"enable\": true }, \"margin\": { \"bottom\": 10, \"left\": 15, \"right\": 15, \"top\": 10 } } }, \"contentType\": \"Text\", \"conversionState\": \"DIGITAL_EDIT\", \"height\": 620, \"strokeGroups\": [ { \"penStyle\": \"color: #120f51;↵-myscript-pen-width: 2;\", \"penStyleClasses\": \"ink mycolor\", \"strokes\": [ { \"id\": \"string\", \"p\": [ 0.5, 0.8221720589961077, 0.7145158745241171, 0.6761535882018319, 0.6761535882018319, 0.6761535882018319, 0.7145158745241171, 0.6831899108492184, 0.7145158745241171, 0.6831899108492184, 0.6831899108492184 ], \"pointerId\": 0, \"pointerType\": \"PEN\", \"t\": [ 1516717383637, 1516717383677, 1516717383694, 1516717383711, 1516717383727, 1516717383744, 1516717383761, 1516717383777, 1516717383794, 1516717383811, 1516717383827 ], \"x\": [ 289, 290, 290, 290, 290, 290, 290, 291, 291, 292, 293 ], \"y\": [ 215, 218, 222, 225, 228, 231, 235, 238, 242, 245, 248 ] } ] } ], \"theme\": \"ink {color: #000000; -myscript-pen-width: 1; -myscript-pen-fill-style: none; -myscript-pen-fill-color: #FFFFFF00;} mycolor {color: #120f51;} .math { font-family: STIXGeneral;} .math-solved {font-family: STIXGeneral; color: #A8A8A8FF;} .text {font-family: Open Sans; font-size: 10;}\", \"width\": 722, \"xDPI\": 96, \"yDPI\": 96}"


Answer

Dear 天美意 深圳,


currently, we are questionning about your request. What are you trying to recognize: text, math, diagram, raw-content? Indeed, in your request, you set all the modes, while only one should be set.


In the same way, why are you adding "customLexicon", "customResources" and "customGrammarContent" fields: "customLexicon\": [ \"word1\", \"word2\" ], \"customResources\": [ \"your_custom_resource\" ] } ? These are not necessary fr a "first request"?


All this lead to a badly formed request.


For information, you can refer to the following samples, that show how you can use our REST API:

For TEXT:

-https://github.com/MyScript/myscript-text-web/blob/master/src/demo-app/examples/v4/iink_rest.html

-https://myscript.github.io/myscript-text-web/#/elements/myscript-text-web/demos/other-examples (for the latter, the source code is nto available, this should be fixed shortly)

for Math:

-https://github.com/MyScript/myscript-math-web/blob/master/src/demo-app/examples/v4/iink_rest.html

-https://myscript.github.io/myscript-math-web/#/elements/myscript-math-web/demos/other-examples


Reworking your request considering you just want to recognize text, it worked properly.


Please find it below.


Best regards,


Oliver


curl -X POST \

  https://cloud.myscript.com/api/v4.0/iink/batch \

  -H 'Accept: application/vnd.myscript.jiix,application/json' \

  -H 'Content-Type: application/json' \

  -H 'applicationKey: xxx' \

  -H 'hmackey: xxx' \

  -d '{

  "configuration": {

    "export": {

      "image-resolution": 300,

      "jiix": {

        "bounding-box": false,

        "strokes": true,

        "style": false,

        "text": {

          "chars": false,

          "words": true

        }

      }

    },

    "lang": "en_US"

  },

  "contentType": "Text",

  "conversionState": "DIGITAL_EDIT",

  "height": 620,

  "strokeGroups": [

    {

      "penStyle": "color: #120f51;↵-myscript-pen-width: 2;",

      "penStyleClasses": "ink mycolor",

      "strokes": [

        {

          "id": "string",

          "p": [

            0.5,

            0.8221720589961077,

            0.7145158745241171,

            0.6761535882018319,

            0.6761535882018319,

            0.6761535882018319,

            0.7145158745241171,

            0.6831899108492184,

            0.7145158745241171,

            0.6831899108492184,

            0.6831899108492184

          ],

          "pointerId": 0,

          "pointerType": "PEN",

          "t": [

            1516717383637,

            1516717383677,

            1516717383694,

            1516717383711,

            1516717383727,

            1516717383744,

            1516717383761,

            1516717383777,

            1516717383794,

            1516717383811,

            1516717383827

          ],

          "x": [

            289,

            290,

            290,

            290,

            290,

            290,

            290,

            291,

            291,

            292,

            293

          ],

          "y": [

            215,

            218,

            222,

            225,

            228,

            231,

            235,

            238,

            242,

            245,

            248

          ]

        }

      ]

    }

  ],

  "theme": "ink {color: #000000; -myscript-pen-width: 1; -myscript-pen-fill-style: none; -myscript-pen-fill-color: #FFFFFF00;} mycolor {color: #120f51;} .math { font-family: STIXGeneral;} .math-solved {font-family: STIXGeneral; color: #A8A8A8FF;} .text {font-family: Open Sans; font-size: 10;}",

  "width": 722,

  "xDPI": 96,

  "yDPI": 96

}

'