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 (世界標準時間)。"],[[["Utilize the AMP URL API to find corresponding AMP URLs and serve those versions to users."],["The API allows matching up to 50 URLs at once by sending a POST request with a JSON payload containing the URLs."],["Include a developer key in the request header for authorization purposes."],["The API response provides both the original AMP URL and the Google AMP Cache URL; prioritize using the cached version (`cdnAmpUrl`)."],["Implement redirects for moved AMP files to ensure proper resolution by the Google AMP Cache."]]],["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"]]