I have created API key from here.com
key generated and test is also working as intended.
but while creating a function based on API key, I am getting “cause” : “App mnTrY8NvPwu6nt8h8AR6 credentials do not authorize access to per… (use muteHttpExceptions option to examine full response)” error.
function getParkingDetails2(location) {
try {
// Step 1: Get coordinates for the location
const geocodeUrl = `https://geocode.search.hereapi.com/v1/geocode?
q=${encodeURIComponent(location)}&apiKey=${HERE_API_KEY}`;
const geocodeResponse = UrlFetchApp.fetch(geocodeUrl);
const geocodeData = JSON.parse(geocodeResponse.getContentText());
if (!geocodeData.items || geocodeData.items.length === 0) {
return { error: `No coordinates found for location: ${location}` };
}
const { lat, lng } = geocodeData.items[0].position;
// Step 2: Define a bounding box around the coordinates
const delta = 0.05; // Adjust for search area size
const bbox = `${lat + delta},${lng - delta},${lat - delta},${lng + delta}`;
// Step 3: Fetch parking details using HERE Parking API
const parkingUrl = `https://osp.cc.api.here.com/parking/segments?
bbox=${bbox}&apiKey=${HERE_API_KEY}`;
const parkingResponse = UrlFetchApp.fetch(parkingUrl);
const parkingData = JSON.parse(parkingResponse.getContentText());
if (!parkingData || parkingData.length === 0) {
return { error: `No parking data found near ${location}` };
}
return { parkingSegments: parkingData };
} catch (error) {
Logger.log('Error fetching parking details: ' + error.message);
return { error: 'An unexpected error occurred while retrieving parking data' };
}
}
function testGetParkingDetails() {
const location = 'Washington';
const parkingDetails = getParkingDetails2(location);
Logger.log(parkingDetails);
}
Can someone help on it please