在Google Apps Script中如何指定Content API 2.1版本?
Hey there! I see you're stuck trying to target version 2.1 of the Shopping Content API in your Apps Script—passing a version: 2.1 parameter isn't working, and I know exactly why.
In Google Apps Script's advanced services, API versions aren't specified via request parameters like that. Instead, you need to use a version-specific service name after enabling the correct API version first. Let's walk through this:
Step 1: Enable v2.1 in Advanced Google Services
- Open your Apps Script editor. If you're working from a Google Sheet/Doc, go to Extensions > Apps Script to get there.
- Click on the Services tab (left sidebar, looks like a puzzle piece), then hit Add service.
- Find Shopping Content API in the list, then use the dropdown to select v2.1 (not the default v2) and click Add.
Step 2: Update Your Code to Use the Versioned Service
The default ShoppingContent object in Apps Script links to the v2 API. To call v2.1, you need to replace that with ShoppingContent_v2_1. Here's your modified code snippet:
var products = ShoppingContent_v2_1.Products.list(merchantId, { pageToken: pageToken, maxResults: maxResults, includeInvalidInsertedItems: true });
Quick Fix if v2.1 Isn't Showing Up
If you don't see v2.1 as an option in the Advanced Services menu, head to your project's Google Cloud Console, search for "Shopping Content API", make sure version 2.1 is enabled there, then go back to Apps Script and refresh the Services list—it should appear right away.
That should do the trick! You'll be calling the 2.1 version of the API successfully now.
内容的提问来源于stack exchange,提问作者Charles Bannister




