基本閱讀
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Slides API 可讓您讀取簡報、頁面和頁面元素資料。本頁的範例說明如何使用 presentations.get
和 presentations.pages.get
方法執行常見的讀取作業。
這些範例使用下列預留位置:
- PRESENTATION_ID:指出您提供簡報 ID 的位置。您可以從簡報網址找出這個 ID 的值。
- PAGE_ID:指出您提供網頁物件 ID 的位置。您可以從網址或透過 API 讀取要求,擷取這個值。
這些範例以 HTTP 要求的形式呈現,因此不限語言。這些範例會從這個範例簡報讀取資料,該簡報的1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc
為PRESENTATION_ID。這份簡報中第一張投影片的PAGE_ID是 ge63a4b4_1_0
。
這裡的範例會使用欄位遮罩,只傳回簡報、投影片和頁面元素的特定要求資訊。使用欄位遮罩也能提升效能。
讀取投影片物件 ID
下列 presentations.get
程式碼範例顯示如何從簡報中擷取所有投影片物件 ID 的清單。系統會依投影片順序傳回 ID,並可用於後續 API 要求中,指出特定投影片。您可以使用 fields=masters.objectId
和 fields=layout.objectId
,以相同方式取得主頁面和版面配置頁面的物件 ID。
以下是讀取投影片物件 ID 的要求通訊協定:
GET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID?fields=slides.objectId
回應包含 Presentation
物件,內含要求的物件 ID:
{
"slides": [
{
"objectId": "ge63a4b4_1_0"
},
{
"objectId": "ge63a4b4_1_9"
},
{
"objectId": "ge63a4b4_1_23"
},
{
"objectId": "ge63a4b4_1_35"
},
{
"objectId": "ge63a4b4_1_43"
}
]
}
從網頁讀取元素物件 ID
下列 presentations.pages.get
程式碼範例說明如何擷取網頁上所有網頁元素的物件 ID 清單。
以下是從網頁讀取元素物件 ID 的要求通訊協定:
GET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID/pages/PAGE_ID?fields=pageElements.objectId
回應包含 Page
物件,內含要求的物件 ID:
{
"pageElements": [
{
"objectId": "ge63a4b4_1_5"
},
{
"objectId": "ge63a4b4_1_6"
},
{
"objectId": "ge63a4b4_1_7"
},
{
"objectId": "ge63a4b4_1_8"
}
]
}
從頁面讀取形狀元素
下列
presentations.pages.get
程式碼範例說明如何擷取網頁上的所有 Shapes
清單。如要擷取其他PageElement
,請使用 fields
參數指定。舉例來說,如果網頁上存在 line
和 table
頁面元素,fields=pageElements(line,table)
就只會傳回這些元素的相關資訊。
以下是從網頁讀取形狀元素的要求通訊協定:
GET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID/pages/PAGE_ID?fields=pageElements.shape
回覆包含 Page
物件,內含所要求的形狀元素。空白大括號表示頁面元素並非形狀類型,在本例中,這些元素是圖片頁面元素。
{
"pageElements": [
{},
{},
{
"shape": {
"shapeProperties" {
"outline" {
"dashStyle": "SOLID",
"outlineFill": {
"solidFill": {
"alpha": 1,
"color": {
"rgbColor": {}
}
},
},
"propertyState": "NOT_RENDERED",
"weight": {
"magnitude": 9525,
"unit": "EMU"
}
},
"shadow": {
"alignment": "BOTTOM_LEFT",
"alpha": 1,
"blurRadius": {
"unit": "EMU"
},
"color": {
"rgbColor": {}
},
"propertyState": "NOT_RENDERED",
"rotateWithShape": false,
"transform": {
"scaleX": 1,
"scaleY": 1,
"unit": "EMU"
},
"type": "OUTER"
},
"shapeBackgroundFill" : {
"propertyState": "NOT_RENDERED",
"solidFill": {
"alpha": 1,
"color": {
"rgbColor: {
"blue": 1,
"green": 1,
"red": 1
}
}
}
}
},
"shapeType": "TEXT_BOX",
"text": {
"textElements": [
{
"endIndex": 11,
"paragraphMarker": {
"style": {
"alignment": "START",
"direction": "LEFT_TO_RIGHT",
"indentEnd": {
"unit": "PT"
},
"indentFirstLine": {
"unit": "PT"
},
"indentStart": {
"unit": "PT"
},
"lineSpacing": 100,
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"unit": "PT"
},
"spacingMode": "COLLAPSE_LISTS"
}
}
},
{
"endIndex": 11,
"textRun": {
"content": "Baby Album\n",
"style": {
"backgroundColor": {},
"baselineOffset": "NONE",
"bold": false,
"fontFamily": "Arial",
"fontSize": {
"magnitude": 14,
"unit": "PT"
},
"foregroundColor": {
"opaqueColor": {
"rgbColor": {}
}
},
"italic": false,
"smallCaps": false,
"strikethrough": false,
"underline": false
}
}
}
]
}
}
},
...
]
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Basic reading\n\nThe Google Slides API lets you read presentation, page, and page element data. The\nexamples on this page show how to perform common read operations using both the\n[`presentations.get`](/workspace/slides/api/reference/rest/v1/presentations/get) and\n[`presentations.pages.get`](/workspace/slides/api/reference/rest/v1/presentations.pages/get)\nmethods.\n\nThese examples use the following placeholders:\n\n- \u003cvar translate=\"no\"\u003ePRESENTATION_ID\u003c/var\u003e---Indicates where you provide the [presentation\n ID](/workspace/slides/api/guides/overview#the_structure_of_a_presentation). You can discover the value for this ID from the presentation URL.\n- \u003cvar translate=\"no\"\u003ePAGE_ID\u003c/var\u003e---Indicates where you provide the [page object\n ID](/workspace/slides/api/guides/overview#working_with_object_ids). You can retrieve the value for this from the URL or by using an API read request.\n\nThese examples are presented as HTTP requests to be language neutral. The\nexamples read from this [example\npresentation](https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit),\nthat has `1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc` as its\n\u003cvar translate=\"no\"\u003ePRESENTATION_ID\u003c/var\u003e. The \u003cvar translate=\"no\"\u003ePAGE_ID\u003c/var\u003e of the\n[first\nslide](https://docs.google.com/presentation/d/1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc/edit#slide=id.ge63a4b4_1_0)\nin this presentation is `ge63a4b4_1_0`.\n\nThe examples here use [field masks](/workspace/slides/api/guides/field-masks) to only\nreturn specific requested information about the presentation, slide, and page\nelement. Using field masks also improves performance.\n\nRead slide object IDs\n---------------------\n\nThe following\n[`presentations.get`](/workspace/slides/api/reference/rest/v1/presentations/get) code\nsample shows how to retrieve a list of all the slide object IDs from the\npresentation. The IDs are returned in the slide presentation order, and can be\nused to indicate specific slides in subsequent API requests. You can get the\nobject IDs of master and layout pages the same way, using\n`fields=masters.objectId` and `fields=layout.objectId`.\n\nThe following is the request protocol to read slide object IDs:\n\n\u003cbr /\u003e\n\n```\nGET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID?fields=slides.objectId\n```\n\nThe response consists of a\n[`Presentation`](/workspace/slides/api/reference/rest/v1/presentations#resource:-presentation)\nobject containing the object IDs requested: \n\n```scdoc\n{\n \"slides\": [\n {\n \"objectId\": \"ge63a4b4_1_0\"\n },\n {\n \"objectId\": \"ge63a4b4_1_9\"\n },\n {\n \"objectId\": \"ge63a4b4_1_23\"\n },\n {\n \"objectId\": \"ge63a4b4_1_35\"\n },\n {\n \"objectId\": \"ge63a4b4_1_43\"\n }\n ]\n}\n```\n\nRead element object IDs from a page\n-----------------------------------\n\nThe following\n[`presentations.pages.get`](/workspace/slides/api/reference/rest/v1/presentations.pages/get)\ncode sample shows how to retrieve a list of object IDs for all the page elements\non a page.\n\nThe following is the request protocol to read element object IDs from a page:\n\n\u003cbr /\u003e\n\n```\nGET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID/pages/PAGE_ID?fields=pageElements.objectId\n```\n\nThe response consists of a\n[`Page`](/workspace/slides/api/reference/rest/v1/presentations.pages#resource-page) object\ncontaining the object IDs requested: \n\n```scdoc\n{\n \"pageElements\": [\n {\n \"objectId\": \"ge63a4b4_1_5\"\n },\n {\n \"objectId\": \"ge63a4b4_1_6\"\n },\n {\n \"objectId\": \"ge63a4b4_1_7\"\n },\n {\n \"objectId\": \"ge63a4b4_1_8\"\n }\n ]\n}\n```\n\nRead shape elements from a page\n-------------------------------\n\nThe following\n[`presentations.pages.get`](/workspace/slides/api/reference/rest/v1/presentations.pages/get)\ncode sample shows how to retrieve a list of all\n[`Shapes`](/workspace/slides/api/reference/rest/v1/presentations.pages/shapes#Page.Shape/)\non a page. You can retrieve other\n[`PageElement`](/workspace/slides/api/reference/rest/v1/presentations.pages#Page.PageElement)\nkinds by specifying them using the `fields` parameter. For example,\n`fields=pageElements(line,table)` only returns information about\n[`line`](/workspace/slides/api/reference/rest/v1/presentations.pages/lines#Page.Line) and\n[`table`](/workspace/slides/api/reference/rest/v1/presentations.pages/tables#Page.Table)\npage elements, if any are present on the page.\n| The Slides API [`presentations.pages.get`](/workspace/slides/api/reference/rest/v1/presentations.pages/get) request can return every property a shape has, including ones the API can't edit.\n\nThe following is the request protocol to read shape elements from a page:\n\n\u003cbr /\u003e\n\n```\nGET https://slides.googleapis.com/v1/presentations/PRESENTATION_ID/pages/PAGE_ID?fields=pageElements.shape\n```\n\nThe response consists of a\n[`Page`](/workspace/slides/api/reference/rest/v1/presentations.pages#resource-page) object\ncontaining the shape elements requested. The empty braces indicate page elements\nthat are not of the shape type; in this case, they're image page elements. \n\n```carbon\n{\n \"/workspace/slides/api/reference/rest/v1/presentations.pages#Page.PageElement\": [\n {},\n {},\n {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/shapes#Page.Shape/\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/shapes#Page.ShapeProperties\" {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.Outline\" {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.DashStyle\": \"SOLID\",\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.OutlineFill\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.SolidFill\": {\n \"alpha\": 1,\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.OpaqueColor\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.RgbColor\": {}\n }\n },\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.PropertyState\": \"NOT_RENDERED\",\n \"/workspace/slides/api/reference/rest/v1/Dimension\": {\n \"magnitude\": 9525,\n \"/workspace/slides/api/reference/rest/v1/Unit\": \"EMU\"\n }\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.Shadow\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.RectanglePosition\": \"BOTTOM_LEFT\",\n \"alpha\": 1,\n \"/workspace/slides/api/reference/rest/v1/Dimension\": {\n \"/workspace/slides/api/reference/rest/v1/Unit\": \"EMU\"\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.OpaqueColor\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.RgbColor\": {}\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.PropertyState\": \"NOT_RENDERED\",\n \"rotateWithShape\": false,\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.AffineTransform\": {\n \"scaleX\": 1,\n \"scaleY\": 1,\n \"/workspace/slides/api/reference/rest/v1/Unit\": \"EMU\"\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/shapes#Page.Type_2\": \"OUTER\"\n },\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/shapes#Page.ShapeBackgroundFill\" : {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.PropertyState\": \"NOT_RENDERED\",\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.SolidFill\": {\n \"alpha\": 1,\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.OpaqueColor\": {\n \"/workspace/slides/api/reference/rest/v1/presentations.pages/other#Page.RgbColor: {\n \"blue\": 1,\n \"green\": 1,\n \"red\": 1\n }\n }\n }\n }\n },\n \"shapeType\": \"TEXT_BOX\",\n \"text\": {\n \"textElements\": [\n {\n \"endIndex\": 11,\n \"paragraphMarker\": {\n \"style\": {\n \"alignment\": \"START\",\n \"direction\": \"LEFT_TO_RIGHT\",\n \"indentEnd\": {\n \"unit\": \"PT\"\n },\n \"indentFirstLine\": {\n \"unit\": \"PT\"\n },\n \"indentStart\": {\n \"unit\": \"PT\"\n },\n \"lineSpacing\": 100,\n \"spaceAbove\": {\n \"unit\": \"PT\"\n },\n \"spaceBelow\": {\n \"unit\": \"PT\"\n },\n \"spacingMode\": \"COLLAPSE_LISTS\"\n }\n }\n },\n {\n \"endIndex\": 11,\n \"textRun\": {\n \"content\": \"Baby Album\\n\",\n \"style\": {\n \"backgroundColor\": {},\n \"baselineOffset\": \"NONE\",\n \"bold\": false,\n \"fontFamily\": \"Arial\",\n \"fontSize\": {\n \"magnitude\": 14,\n \"unit\": \"PT\"\n },\n \"foregroundColor\": {\n \"opaqueColor\": {\n \"rgbColor\": {}\n }\n },\n \"italic\": false,\n \"smallCaps\": false,\n \"strikethrough\": false,\n \"underline\": false\n }\n }\n }\n ]\n }\n }\n },\n ...\n ]\n}\n```"]]