基本朗读
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Google Slides API,您可以读取演示文稿、页面和页面元素数据。本页面的示例展示了如何使用 presentations.get
和 presentations.pages.get
方法执行常见的读取操作。
这些示例使用以下占位符:
- PRESENTATION_ID - 表示您提供演示文稿 ID 的位置。您可以通过演示网址发现此 ID 的值。
- PAGE_ID - 指示您提供网页对象 ID 的位置。您可以通过网址或使用 API 读取请求来检索此值。
这些示例以 HTTP 请求的形式呈现,不涉及具体语言。这些示例从这个示例演示文稿中读取数据,该演示文稿的 PRESENTATION_ID 为 1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc
。相应演示文稿中第一张幻灯片的 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
的列表。您可以使用 fields
参数指定其他 PageElement
类型。例如,fields=pageElements(line,table)
仅返回 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
}
}
}
]
}
}
},
...
]
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):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```"]]