Conversation
* fix: migrate Foursquare API to new Places API endpoints * docs: update readme * feat: add fetch error handling to the Foursquare API example --------- Co-authored-by: Yashar Fakhari <6448697+YasharF@users.noreply.github.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| @@ -32,29 +32,41 @@ exports.getApi = (req, res) => { | |||
| */ | |||
| exports.getFoursquare = async (req, res, next) => { | |||
There was a problem hiding this comment.
Code Review
This pull request updates the Foursquare integration to use the latest Places API and Service API Keys, including updates to documentation, environment variables, and the controller logic. While the implementation adds better error handling and simplifies the UI, several critical issues were identified: the API headers and authentication format are incorrect for Foursquare v3, the API domain used is for enterprise services rather than the standard v3 API, and the view incorrectly attempts to access coordinates directly instead of through the nested geocodes.main object.
| 'X-Places-Api-Version': '2025-06-17', | ||
| authorization: `Bearer ${process.env.FOURSQUARE_APIKEY}`, |
There was a problem hiding this comment.
The Foursquare Places API (v3) uses the fsq-version header for versioning (in YYYYMMDD format) and requires the API key to be provided directly in the Authorization header without the Bearer prefix. Using X-Places-Api-Version and the Bearer prefix will likely result in authentication or versioning errors.
| 'X-Places-Api-Version': '2025-06-17', | |
| authorization: `Bearer ${process.env.FOURSQUARE_APIKEY}`, | |
| 'fsq-version': '20231101', | |
| authorization: process.env.FOURSQUARE_APIKEY, |
| fetchJson('https://places-api.foursquare.com/places/search?ll=47.609657,-122.342148&limit=10', options, 'Foursquare search'), | ||
| fetchJson('https://places-api.foursquare.com/places/427ea800f964a520b1211fe3', options, 'Foursquare venue detail'), |
There was a problem hiding this comment.
The standard Foursquare Places API v3 endpoints use the api.foursquare.com/v3 domain. The places-api.foursquare.com domain is typically used for specific enterprise services and may not be compatible with the standard API keys or the response schema expected by the rest of this controller and view.
| fetchJson('https://places-api.foursquare.com/places/search?ll=47.609657,-122.342148&limit=10', options, 'Foursquare search'), | |
| fetchJson('https://places-api.foursquare.com/places/427ea800f964a520b1211fe3', options, 'Foursquare venue detail'), | |
| fetchJson('https://api.foursquare.com/v3/places/search?ll=47.609657,-122.342148&limit=10', options, 'Foursquare search'), | |
| fetchJson('https://api.foursquare.com/v3/places/427ea800f964a520b1211fe3', options, 'Foursquare venue detail'), |
| img.img-thumbnail(src=photo.prefix + '400x400' + photo.suffix, alt=venueDetail.name, width='100%') | ||
| else | ||
| p No photos available. | ||
| | located at #{ venueDetail.location.address || 'N/A' }, #{ venueDetail.location.locality || 'N/A' }, #{ venueDetail.location.region || 'N/A' }. (longitude: #{ venueDetail.longitude }, latitude: #{ venueDetail.latitude }) |
There was a problem hiding this comment.
The Foursquare Places API response structure nests geographic coordinates under geocodes.main. Accessing venueDetail.longitude and venueDetail.latitude directly will result in undefined values being displayed in the UI.
| located at #{ venueDetail.location.address || 'N/A' }, #{ venueDetail.location.locality || 'N/A' }, #{ venueDetail.location.region || 'N/A' }. (longitude: #{ venueDetail.geocodes.main.longitude }, latitude: #{ venueDetail.geocodes.main.latitude })
Checklist
npm run lint,npm test, andnpm run test:e2e-nokeypass locally.--no-verifywas not used when using git commitDescription
Screenshots of UI changes (browser) and logs/test results (console, terminal, shell, cmd)