Method: ampUrls.batchGet
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
HTTP 要求
POST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet
這個網址使用 Google API HTTP 註解語法。
要求主體
要求主體的資料會採用以下結構:
JSON 表示法 |
{
"urls": [
string
]
"lookupStrategy": enum(LookupStrategy),
} |
欄位 |
urls[] |
string
要查詢已配對的 AMP 網址的網址清單。網址區分大小寫。每次查詢最多 50 個網址 (請參閱用量限制)。
|
lookupStrategy |
enum(LookupStrategy )
要求的 lookupStrategy。
|
回應主體
如果成功,回應主體即會包含具有以下結構的資料:
JSON 表示法 |
{
"ampUrls": [
{
object(AmpUrl)
}
],
"urlErrors": [
{
object(AmpUrlError)
}
],
}
|
欄位 |
ampUrls[] |
object(AmpUrl )
針對 BatchAmpUrlsRequest 中的每個網址,網址回應。回應的順序可能與批次要求中的網址順序不同。如果 BatchAmpUrlsRequest 含有重複的網址,則 AmpUrl 只會產生一次。
|
urlErrors[] |
object(AmpUrlError )
要求網址不含 AMP 網址的錯誤訊息。
|
搜尋策略
列舉 |
FETCH_LIVE_DOC |
FETCH_LIVE_DOC 策略涉及在索引中找不到網址的即時文件擷取作業。Google 會即時檢索在索引中找不到的所有要求網址,驗證是否有對應的 AMP 網址。這項策略的涵蓋範圍較長,但即時檢索功能會導入額外的延遲時間。這是預設策略。採用這項策略的應用程式應會設定較高的 API 呼叫 HTTP 逾時時間。 |
IN_INDEX_DOC |
IN_INDEX_DOC 策略會略過擷取索引中找不到網址的即時文件。針對需要低延遲延遲時間的應用程式,建議使用 IN_INDEX_DOC 策略。 |
AMP 網址
JSON 表示法 |
{
"originalUrl": string,
"ampUrl": string,
"cdnAmpUrl": string,
} |
欄位 |
originalUrl |
string
原始非 AMP 網址。
|
ampUrl |
string
指向發布者網路伺服器的 AMP 網址。
|
cdnAmpUrl |
string
指向 Google AMP 快取中快取文件的 AMP 快取網址。
|
AmpUrlError
JSON 表示法 |
{
"errorCode": enum(ErrorCode),
"errorMessage": string,
"originalUrl": string,
} |
欄位 |
errorCode |
enum(ErrorCode )
API 呼叫的錯誤代碼。
|
errorMessage |
string
選填的描述性錯誤訊息。
|
originalUrl |
string
原始非 AMP 網址。
|
ErrorCode
列舉 |
ERROR_CODE_UNSPECIFIED |
未指定錯誤。 |
INPUT_URL_NOT_FOUND |
表示系統無法在索引中找到你要求的網址,原因可能是找不到 Googlebot、無法存取 Googlebot 或其他網址的錯誤。 |
NO_AMP_URL |
表示找不到與要求網址對應的 AMP 網址。 |
APPLICATION_ERROR |
表示伺服器發生某種應用程式錯誤。建議客戶重試。 |
URL_IS_VALID_AMP |
已淘汰:表示要求的網址是有效的 AMP 網址。這是非錯誤狀態,不應該做為成功或失敗跡象。我們將在日後的 API 版本中將其移除。 |
URL_IS_INVALID_AMP |
表示找到與要求網址對應的 AMP 網址,但不是有效的 AMP HTML。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-08-30 (世界標準時間)。
[null,null,["上次更新時間:2023-08-30 (世界標準時間)。"],[[["\u003cp\u003eReturns AMP URLs and their corresponding AMP Cache URLs for given input URLs.\u003c/p\u003e\n"],["\u003cp\u003eUses a batch request containing up to 50 URLs and a lookup strategy (FETCH_LIVE_DOC or IN_INDEX_DOC).\u003c/p\u003e\n"],["\u003cp\u003eThe response includes the AMP URL and AMP Cache URL for successful lookups and error details for unsuccessful ones.\u003c/p\u003e\n"],["\u003cp\u003ePossible error codes include URL not found, no corresponding AMP URL, application error, and invalid AMP HTML.\u003c/p\u003e\n"],["\u003cp\u003eLeverages the Google AMP Cache for faster delivery of AMP content.\u003c/p\u003e\n"]]],["This API facilitates retrieving AMP URLs and their corresponding Google AMP Cache URLs. It uses a `POST` request to `ampUrls:batchGet`, taking a list of up to 50 URLs and a `lookupStrategy` (either `FETCH_LIVE_DOC` or `IN_INDEX_DOC`) in the request body. The response contains an array of `ampUrls` (with original, AMP, and cache URLs) and `urlErrors` (with error codes and messages). Error codes are specified for issues like \"URL not found\" and \"no AMP URL found.\"\n"],null,["# Method: ampUrls.batchGet\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Request body](#body.request_body)\n - [JSON representation](#body.request_body.SCHEMA_REPRESENTATION)\n- [Response body](#body.response_body)\n - [JSON representation](#body.BatchGetAmpUrlsResponse.SCHEMA_REPRESENTATION)\n- [LookupStrategy](#LookupStrategy)\n- [AmpUrl](#AmpUrl)\n - [JSON representation](#AmpUrl.SCHEMA_REPRESENTATION)\n- [AmpUrlError](#AmpUrlError)\n - [JSON representation](#AmpUrlError.SCHEMA_REPRESENTATION)\n- [ErrorCode](#ErrorCode)\n- [Try it!](#try-it)\n\nReturns AMP URL(s) and equivalent [AMP Cache URL(s)](/amp/cache/overview#amp-cache-url-format).\n\n### HTTP request\n\n`POST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet`\n\nThe URL uses [Google API HTTP annotation](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto) syntax.\n\n### Request body\n\nThe request body contains data with the following structure:\n\n| JSON representation ||\n|--------------------------------------------------------------------------------|---|\n| ```gdscript { \"urls\": [ string ] \"lookupStrategy\": enum(LookupStrategy), } ``` |\n\n| Fields ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `urls[]` | `string` List of URLs to look up for the paired AMP URLs. The URLs are case-sensitive. Up to 50 URLs per lookup (see [Usage Limits](/amp/cache/reference/limits)). |\n| `lookupStrategy` | `enum(`[LookupStrategy](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#LookupStrategy)`)` The lookupStrategy being requested. |\n\n### Response body\n\nIf successful, the response body contains data with the following structure:\nBatch AMP URL response.\n\n| JSON representation ||\n|----------------------------------------------------------------------------------------------|---|\n| ```text { \"ampUrls\": [ { object(AmpUrl) } ], \"urlErrors\": [ { object(AmpUrlError) } ], } ``` |\n\n| Fields ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ampUrls[]` | `object(`[AmpUrl](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#AmpUrl)`)` For each URL in BatchAmpUrlsRequest, the URL response. The response might not be in the same order as URLs in the batch request. If BatchAmpUrlsRequest contains duplicate URLs, AmpUrl is generated only once. |\n| `urlErrors[]` | `object(`[AmpUrlError](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#AmpUrlError)`)` The errors for requested URLs that have no AMP URL. |\n\nLookupStrategy\n--------------\n\n| Enums ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `FETCH_LIVE_DOC` | FETCH_LIVE_DOC strategy involves live document fetch of URLs not found in the index. Any request URL not found in the index is crawled in realtime to validate if there is a corresponding AMP URL. This strategy has higher coverage but with extra latency introduced by realtime crawling. This is the default strategy. Applications using this strategy should set higher HTTP timeouts of the API calls. |\n| `IN_INDEX_DOC` | IN_INDEX_DOC strategy skips fetching live documents of URL(s) not found in index. For applications which need low latency use of IN_INDEX_DOC strategy is recommended. |\n\nAmpUrl\n------\n\nAMP URL response for a requested URL.\n\n| JSON representation ||\n|-------------------------------------------------------------------------------|---|\n| ```text { \"originalUrl\": string, \"ampUrl\": string, \"cdnAmpUrl\": string, } ``` |\n\n| Fields ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------|\n| `originalUrl` | `string` The original non-AMP URL. |\n| `ampUrl` | `string` The AMP URL pointing to the publisher's web server. |\n| `cdnAmpUrl` | `string` The [AMP Cache URL](/amp/cache/overview#amp-cache-url-format) pointing to the cached document in the Google AMP Cache. |\n\nAmpUrlError\n-----------\n\nAMP URL Error resource for a requested URL that couldn't be found.\n\n| JSON representation ||\n|--------------------------------------------------------------------------------------------------|---|\n| ```gdscript { \"errorCode\": enum(ErrorCode), \"errorMessage\": string, \"originalUrl\": string, } ``` |\n\n| Fields ||\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `errorCode` | `enum(`[ErrorCode](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#ErrorCode)`)` The error code of an API call. |\n| `errorMessage` | `string` An optional descriptive error message. |\n| `originalUrl` | `string` The original non-AMP URL. |\n\nErrorCode\n---------\n\nError codes for a batch AMP URL lookup.\n\n| Enums ||\n|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ERROR_CODE_UNSPECIFIED` | Not specified error. |\n| `INPUT_URL_NOT_FOUND` | Indicates the requested URL is not found in the index, possibly because it's unable to be found, not able to be accessed by Googlebot, or some other error. |\n| `NO_AMP_URL` | Indicates no AMP URL has been found that corresponds to the requested URL. |\n| `APPLICATION_ERROR` | Indicates some kind of application error occurred at the server. Client advised to retry. |\n| `URL_IS_VALID_AMP` | DEPRECATED: Indicates the requested URL is a valid AMP URL. This is a non-error state, should not be relied upon as a sign of success or failure. It will be removed in future versions of the API. |\n| `URL_IS_INVALID_AMP` | Indicates that an AMP URL has been found that corresponds to the request URL, but it is not valid AMP HTML. |\n\nTry it!\n-------"]]