|
| 1 | +# Google Places API Migration Fix |
| 2 | + |
| 3 | +## Problem |
| 4 | +The `get_place_details` tool was returning HTTP 403 errors with the message: |
| 5 | +``` |
| 6 | +Failed to get place details for ChIJQ2BmJhVwhlQRPkt6FWiet90: You're calling a legacy API, which is not enabled for your project. To get newer features and more functionality, switch to the Places API (New) or Routes API. |
| 7 | +``` |
| 8 | + |
| 9 | +## Solution |
| 10 | +Migrated from the legacy Google Places API to the new Places API (New) to resolve the HTTP 403 errors and ensure continued functionality. |
| 11 | + |
| 12 | +## Changes Made |
| 13 | + |
| 14 | +### 1. Added New Dependency |
| 15 | +- Added `@googlemaps/places` package (v2.1.0) to `package.json` |
| 16 | +- This is the official Google client library for the new Places API |
| 17 | + |
| 18 | +### 2. Created New Service Class |
| 19 | +- **File**: `src/services/NewPlacesService.ts` |
| 20 | +- Implements the new Places API client |
| 21 | +- Maintains backward compatibility by transforming the new API response format to match the legacy format |
| 22 | +- Handles field mapping and data transformation |
| 23 | + |
| 24 | +### 3. Updated PlacesSearcher |
| 25 | +- **File**: `src/services/PlacesSearcher.ts` |
| 26 | +- Modified `getPlaceDetails()` method to use the new `NewPlacesService` |
| 27 | +- Maintains the same interface and response format for existing code |
| 28 | + |
| 29 | +### 4. Key Features of the New Implementation |
| 30 | +- Uses the new Places API (New) endpoint |
| 31 | +- Proper field mask handling to avoid unnecessary billing |
| 32 | +- Maintains backward compatibility with existing response structure |
| 33 | +- Enhanced error handling for the new API |
| 34 | +- Support for all existing place details fields (name, address, rating, reviews, etc.) |
| 35 | + |
| 36 | +### 5. Testing |
| 37 | +- Created `test-new-api.js` script to verify the new implementation |
| 38 | +- Build process verified to work correctly |
| 39 | +- Maintains existing functionality while using the new API |
| 40 | + |
| 41 | +## Files Modified |
| 42 | +1. `package.json` - Added new dependency |
| 43 | +2. `src/services/NewPlacesService.ts` - New service class (created) |
| 44 | +3. `src/services/PlacesSearcher.ts` - Updated to use new service |
| 45 | +4. `README.md` - Added information about the API migration |
| 46 | +5. `test-new-api.js` - Test script (created) |
| 47 | + |
| 48 | +## How to Apply the Fix |
| 49 | + |
| 50 | +### Option 1: Apply the Patch File |
| 51 | +```bash |
| 52 | +git apply places-api-fix.patch |
| 53 | +``` |
| 54 | + |
| 55 | +### Option 2: Manual Implementation |
| 56 | +1. Install the new dependency: |
| 57 | + ```bash |
| 58 | + npm install @googlemaps/places |
| 59 | + ``` |
| 60 | + |
| 61 | +2. Copy the new service file: |
| 62 | + ```bash |
| 63 | + cp src/services/NewPlacesService.ts /path/to/your/project/src/services/ |
| 64 | + ``` |
| 65 | + |
| 66 | +3. Update `src/services/PlacesSearcher.ts` to import and use the new service: |
| 67 | + ```typescript |
| 68 | + import { NewPlacesService } from "./NewPlacesService.js"; |
| 69 | + |
| 70 | + // In constructor: |
| 71 | + this.newPlacesService = new NewPlacesService(apiKey); |
| 72 | + |
| 73 | + // In getPlaceDetails method: |
| 74 | + const details = await this.newPlacesService.getPlaceDetails(placeId); |
| 75 | + ``` |
| 76 | + |
| 77 | +## Benefits |
| 78 | +- ✅ Resolves HTTP 403 errors from legacy API |
| 79 | +- ✅ Uses the latest Google Places API with improved features |
| 80 | +- ✅ Maintains backward compatibility |
| 81 | +- ✅ Better error handling and field management |
| 82 | +- ✅ Future-proof implementation |
| 83 | + |
| 84 | +## Testing |
| 85 | +To test the fix, run: |
| 86 | +```bash |
| 87 | +export GOOGLE_MAPS_API_KEY="your-api-key" |
| 88 | +node test-new-api.js |
| 89 | +``` |
| 90 | + |
| 91 | +This will test the `get_place_details` functionality with the new API implementation. |
0 commit comments