ลิงก์ไปยังเนื้อหา AMP
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใช้ AMP URL API เพื่อจับคู่ URL กับ URL ของ AMP ที่เกี่ยวข้อง และแสดงเวอร์ชัน AMP แทน
จับคู่ URL กับ URL ของ AMP
ขอ URL ของ AMP ผ่าน:
POST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet
ใส่ URL สูงสุด 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"
แทนที่ URL ด้วย URL ของ AMP
เมธอด batchGet
จะแสดงผลการแมป URL ของ AMP ใน JSON ดังนี้
{
"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"
}
]
}
ทั้ง URL เดิมของ AMP และ URL ที่จัดเก็บไว้ในแคช AMP ของ Google จะแสดงในเนื้อความการตอบกลับ
เราขอแนะนําให้คุณใช้ "cdnAmpUrl"
แทน "ampUrl"
เพื่อให้แอปพลิเคชันมีข้อดีทั้งหมดของแคช AMP ของ Google
ตั้งค่าการเปลี่ยนเส้นทาง
ทุกครั้งที่คุณย้ายตําแหน่งของไฟล์ AMP บนเซิร์ฟเวอร์ ให้ตั้งค่าการเปลี่ยนเส้นทางจากตําแหน่งเก่าไปยังตําแหน่งใหม่
เซิร์ฟเวอร์แคช AMP ของ Google จะติดตามการเปลี่ยนเส้นทางเมื่อแก้ปัญหา URL ของ AMP
หาก URL หนึ่งเปลี่ยนเส้นทางไปยัง URL ของ AMP อื่นที่ถูกต้อง เซิร์ฟเวอร์แคช AMP ของ Google จะแสดงผลและแคชเนื้อหาของการเปลี่ยนเส้นทางที่แก้ไขแล้ว
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2023-08-30 UTC
[[["เข้าใจง่าย","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 UTC"],[[["\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."]]