本文介绍了嵌套API请求中的身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Foursquare场地详细信息传递到场地"列表页面(父级),但是从嵌套函数中接收到一个错误,该错误提取了详细信息.初始列表请求将按预期返回数据,而不会出现错误.如何解决嵌套请求上的身份验证错误?

I'm trying to pass Foursquare venue details to a Venue listing page (parent) but am receiving an error from the nested function that pulls the details. The initial listing request returns data as expected without error. How can I resolve the authentication error on the nested request?

这是错误-

{
  code: 400
  errorDetail: "Missing access credentials. See
  https://developer.foursquare.com/docs/api/configuration/authentication
  for details."
  errorType: "invalid_auth"
}

我在列表函数中调用此函数-

I'm calling this function within the listing function -

    var request = new XMLHttpRequest();

    function getDetails(e){
        requestVenueDetails = 'https://api.foursquare.com/v2/venues/'+e+'&client_id='+{client id}+'&client_secret='+{secret}+'&v='+{version};
        request.open('GET', requestVenueDetails, true);
        request.onload = function()
        {
            var detailsData = JSON.parse(this.response);
            var venueDetails = detailsData;
            console.log(venueDetails, ' return confirmation message');
        }
        request.send();
    }

这是列表功能-

    returnRequest = function(){
        request.onload = function()
        {
            var data = JSON.parse(this.response);
            var venues = data.response.venues;
            console.log(venues);
            if(venues.length>0)
            {
                venues.forEach( venue=> {
            if((venue.location.address != null) && (venue.verified = true))
                    {
                        getDetails(venue.id);
                        {listing html here}
                    }
                });
            }
        request.send();
    }

推荐答案

问题是缺少?"在嵌套请求网址中位于场所ID之后和用户凭据之前.

The problem was a missing '?' in the nested request URL after the venue ID and before the user credentials.

DOH,只需要休息一下眼睛凝视它.

DOH, just needed to stare at it longer with rested eyes.

这篇关于嵌套API请求中的身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 06:21