Authentication error in nested API request

2019-09-20 12:31发布

问题:

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.