Authentication error in nested API request

半世苍凉 提交于 2020-01-07 09:56:24

问题


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?

This is the error -

{
  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();    
    }

Here is the listing function -

    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();
    }

回答1:


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

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



来源:https://stackoverflow.com/questions/56747084/authentication-error-in-nested-api-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!