AMP 內容連結
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 AMP URL API 將網址與對應的 AMP 網址進行比對,並改為放送 AMP 版本。
將網址與 AMP 網址進行比對
透過以下方式要求 AMP 網址:
POST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet
在要求內容中列出最多 50 個網址的酬載:
{"urls": [
"https://www.amp.dev",
"https://www.example.org/article-without-amp-version"
]}
所有的要求都必須透過 X-Authorization 標頭 (X-Goog-Api-Key: YOUR-DEVELOPER-KEY
) 加入開發金鑰。X-Authorization 標頭值區分大小寫。
如果您還沒有開發金鑰,請參閱授權一節,瞭解設定操作說明。
使用 curl 的範例:
curl -i -s -k -X POST -H "Content-Type: application/json" -H "X-Goog-Api-Key: " -d "{urls: ['https://example.com']}" "https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet"
以 AMP 網址取代網址
batchGet
方法會傳回 JSON 中的 AMP 網址對應:
{
"ampUrls": [
{
"originalUrl": "https://example.com",
"ampUrl": "https://example.com",
"cdnAmpUrl":
"https://cdn.ampproject.org/c/s/example.com"
}
],
"urlErrors": [
{
"errorCode": "NO_AMP_URL",
"errorMessage": "AMP URL not found.",
"originalUrl": "http://www.example.com/no-amp-version.html"
}
]
}
原始 AMP 網址和儲存在 Google AMP 快取中儲存的網址都會傳回回應主體。建議您使用 "cdnAmpUrl"
(而非 "ampUrl"
),讓您的應用程式能夠享有 Google AMP 快取的所有優點。
設定重新導向
每次在伺服器上移動 AMP 檔案的位置時,請設定從舊位置重新導向新位置的位置,Google AMP 快取在解析 AMP 網址時採用重新導向。
如果網址重新導向至其他有效的 AMP 網址,Google AMP 快取會傳回已解析的重新導向內容,並快取快取內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-08-30 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2023-08-30 (世界標準時間)。"],[[["\u003cp\u003eUtilize the AMP URL API to find corresponding AMP URLs and serve those versions to users.\u003c/p\u003e\n"],["\u003cp\u003eThe API allows matching up to 50 URLs at once by sending a POST request with a JSON payload containing the URLs.\u003c/p\u003e\n"],["\u003cp\u003eInclude a developer key in the request header for authorization purposes.\u003c/p\u003e\n"],["\u003cp\u003eThe API response provides both the original AMP URL and the Google AMP Cache URL; prioritize using the cached version (\u003ccode\u003ecdnAmpUrl\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eImplement redirects for moved AMP files to ensure proper resolution by the Google AMP Cache.\u003c/p\u003e\n"]]],["To obtain AMP URLs, use the AMP URL API's `batchGet` method via a POST request to `acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet`. Include up to 50 URLs in the request body and a developer key in the `X-Goog-Api-Key` header. The response will provide a JSON mapping, including original and CDN AMP URLs. It's recommended to use `\"cdnAmpUrl\"`. Set up redirects for moved AMP files to ensure the Google AMP Cache resolves and caches the correct content.\n"],null,["# Link to AMP Content\n\nUse the [AMP URL API](/amp/cache/reference/acceleratedmobilepageurl/rest)\nto match URLs to corresponding AMP URLs,\nand serve the AMP versions instead.\n\nMatch URLs to AMP URLs\n----------------------\n\nRequest an AMP URL via: \n\n```\nPOST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet\n```\n\nList [up to 50 URLs](/amp/cache/reference/limits)\nas payload in the request body: \n\n```\n{\"urls\": [\n \"https://www.amp.dev\",\n \"https://www.example.org/article-without-amp-version\"\n]}\n```\n| **Note:** The requested URLs do not need to be in their [canonical forms](https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/discovery).\n\n\nAll requests need to include a development key via X-Authorization header\n(`X-Goog-Api-Key: YOUR-DEVELOPER-KEY`).\nThe X-Authorization header value is case sensitive.\nIf you don't have a development key,\nsee [Authorization](/amp/cache/reference/authorizing) for setup instructions.\n\n\nExample using curl: \n\n```\ncurl -i -s -k -X POST -H \"Content-Type: application/json\" -H \"X-Goog-Api-Key: \" -d \"{urls: ['https://example.com']}\" \"https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet\"\n```\n\nReplace URLs with AMP URLs\n--------------------------\n\nThe [`batchGet` method](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet)\nreturns the AMP URL mapping in JSON: \n\n```\n{ \n \"ampUrls\": [\n { \n \"originalUrl\": \"https://example.com\",\n \"ampUrl\": \"https://example.com\",\n \"cdnAmpUrl\": \n \"https://cdn.ampproject.org/c/s/example.com\"\n }\n ],\n \"urlErrors\": [\n { \n \"errorCode\": \"NO_AMP_URL\",\n \"errorMessage\": \"AMP URL not found.\",\n \"originalUrl\": \"http://www.example.com/no-amp-version.html\"\n }\n ]\n}\n```\n\n\nBoth the original AMP URL\nand the one stored in the Google AMP Cache\nget returned in the\n[response body](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#response-body).\nWe encourage you to use `\"cdnAmpUrl\"`, instead of `\"ampUrl\"`,\nso that your application can have all\n[the benefits of the Google AMP Cache](/amp/cache/overview).\n| **Note:** An error is thrown if no AMP URLs exist (see the [`AmpUrlError` reference](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet#ampurlerror)).\n\nSet up redirects\n----------------\n\nAny time you move the location of AMP files on your server,\nset up redirects from old locations to new locations.\nThe Google AMP Cache follows redirects when resolving AMP URLs.\n\nIf a URL redirects to another valid AMP URL,\nthe Google AMP Cache returns and caches the content of the resolved redirect."]]