Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Ajax中使用IconFinder API使用授权访问令牌获取IConSet_Javascript_Api - Fatal编程技术网

Javascript 如何在Ajax中使用IconFinder API使用授权访问令牌获取IConSet

Javascript 如何在Ajax中使用IconFinder API使用授权访问令牌获取IConSet,javascript,api,Javascript,Api,我在iconFinder上注册了我的应用程序,并使用其JSON Web令牌身份验证来获取访问令牌,然后使用该令牌进行身份验证,但它不起作用 我使用另一个Ajax Get调用,使用授权访问令牌调用其api,然后返回响应(未经授权) 对于访问令牌: var nf_token_url = "https://www.iconfinder.com/api/v3/oauth2/token"; const proxyurl = "https://cors-anywhere.herokuapp.com/";

我在
iconFinder
上注册了我的应用程序,并使用其JSON Web令牌身份验证来获取访问令牌,然后使用该令牌进行身份验证,但它不起作用

我使用另一个Ajax Get调用,使用授权访问令牌调用其api,然后返回响应(未经授权)

对于访问令牌:

var nf_token_url = "https://www.iconfinder.com/api/v3/oauth2/token";
const proxyurl = "https://cors-anywhere.herokuapp.com/";

var form = {
    "grant_type": "jwt_bearer",
    "client_id": "<*>",
    "client_secret": "<*>"
};

var formBody = [];
for (var property in form) {
    var encodedKey = encodeURIComponent(property);
    var encodedValue = encodeURIComponent(form[property]);
    formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");

$.ajax({
    url: proxyurl + nf_token_url,
    headers: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
    },
    data: formBody,
    type: 'post',
    datatype: "jsonp",
    success: function (response) {
        localStorage.setItem('IFT', response.access_token);
    },
    error: function (error) {
        console.log(error);
    }

});


  FOR Get Request Iconsets APi:

  $.ajax({
        url: proxyurl 
        +"https://api.iconfinder.com/v3/icons/searchquery=hello&count=30",
        type: 'GET',
        contentType: "application/json",
        success: function (response) {
            console.log(response);
        },
        error: function (error) {
            console.log(error);
        },
        beforeSend: function (request) {
            request.setRequestHeader("Authorization", "Bearer " + tokken);
        }

    });

我也犯了这个错误。通过在ajax调用中添加客户机和secret解决了我的问题

       $.ajax({
            url: proxyurl +"https://api.iconfinder.com/v3/icons/search?query=hello&count=30",
            type: 'GET',
            data:  {
                "grant_type": "jwt_bearer",
                "client_id": "Your Id",
                "client_secret": "Your Secret"
            },
            contentType: "application/json",
            success: function (response) {
                console.log(response);
            },
            error: function (error) {
                console.log(error);
            },
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", "Bearer " + tokken);
            }

        });

谢谢,它正在工作。。。我现在得到了数据…你解决了我的问题,伙计!!!再次感谢。:)这是我的荣幸,伙计
       $.ajax({
            url: proxyurl +"https://api.iconfinder.com/v3/icons/search?query=hello&count=30",
            type: 'GET',
            data:  {
                "grant_type": "jwt_bearer",
                "client_id": "Your Id",
                "client_secret": "Your Secret"
            },
            contentType: "application/json",
            success: function (response) {
                console.log(response);
            },
            error: function (error) {
                console.log(error);
            },
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", "Bearer " + tokken);
            }

        });