Tag Archives: post

C++ Opencv+BaiDu OCR“error“: “unsupported_grant_type“, “error_description“: “The authorization grant

1. Baidu general reference: authentication mechanism

https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjhhu

Introduction
this document is mainly for HTTP API callers. Baidu AIP open platform uses oauth2.0 authorization to call the open API. When calling the API, you must bring access in the URL_ Token parameter. The process of obtaining access token is as follows:

Get access token
request URL data format

To the authorized service address https://aip.baidubce.com/oauth/2.0/token Send the request (post is recommended), and take the following parameters in the URL:

grant_ Type: required parameter, fixed to client_ credentials;
client_ ID: required parameter, API key applied
client_ Secret: required parameter, the applied secret key;

https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHlA4Fq5eR3LT0vuXV4&c

2. However, the result of my test is:

https://aip.baidubce.com/oauth/2.0/token

Postman test

{

    " grant_type": "client_credentials",

    "client_id": "pGB2vIVTXn9ATexEsqMIDYO",

   "client_secret": "5yNZqWSIuj4PVRGdavjw1e5U3z9K6Kb"

}

Get the token value and display the following results

{
    "error": "unsupported_grant_type",
    "error_description": "The authorization grant type is not supported"
}

How to download files by post submission under Ajax

/*===================Download file
 * options:{
 * url:'',  //Download Url
 * data:{name:value}, //the datas you want to post
 * method:'post'
 * }
 */
var DownLoadFile = function (options) {
    var config = $.extend(true, { method: 'post' }, options);
    var $iframe = $('<iframe id="down-file-iframe" /&>');
    var $form = $('<form target="down-file-iframe" method="' + config.method + '" /&>');
    $form.attr('action', config.url);
    for (var key in config.data) {
        $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" /&>');
    }
    $iframe.append($form);
    $(document.body).append($iframe);
    $form[0].submit();
    $iframe.remove();
}