无法创建包含内容的 google 文档
Unable to create a google document with contents
我目前正在尝试使用 Google 文档 API 创建一个 google 文档。
https://developers.google.com/docs/api/reference/rest/v1/documents/create
我尝试使用网站工具并创建一个包含以下正文的文档。
{
"body": {
"content": [
{
"paragraph": {
"elements": [
{
"textRun": {
"content": "This is a test"
}
}
]
}
}
]
},
"title": "Hello"
}
但是 return 不包含单词 "This is a test"。
return JSON 消息
{
"title": "Hello",
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT"
}
}
},
{
"startIndex": 1,
"endIndex": 2,
"paragraph": {
"elements": [
{
"startIndex": 1,
"endIndex": 2,
"textRun": {
"content": "\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT"
}
}
}
]
},
"documentStyle": {
"background": {
"color": {}
},
"pageNumberStart": 1,
"marginTop": {
"magnitude": 72,
"unit": "PT"
},
"marginBottom": {
"magnitude": 72,
"unit": "PT"
},
"marginRight": {
"magnitude": 72,
"unit": "PT"
},
"marginLeft": {
"magnitude": 72,
"unit": "PT"
},
"pageSize": {
"height": {
"magnitude": 841.8897637795277,
"unit": "PT"
},
"width": {
"magnitude": 595.27559055118115,
"unit": "PT"
}
}
},
"namedStyles": {
"styles": [
{
"namedStyleType": "NORMAL_TEXT",
"textStyle": {
"bold": false,
"italic": false,
"underline": false,
"strikethrough": false,
"smallCaps": false,
"backgroundColor": {},
"foregroundColor": {
"color": {
"rgbColor": {}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
},
"baselineOffset": "NONE"
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"alignment": "START",
"lineSpacing": 115,
"direction": "LEFT_TO_RIGHT",
"spacingMode": "COLLAPSE_LISTS",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"unit": "PT"
},
"borderBetween": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderTop": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderBottom": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderLeft": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderRight": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"indentFirstLine": {
"unit": "PT"
},
"indentStart": {
"unit": "PT"
},
"indentEnd": {
"unit": "PT"
},
"keepLinesTogether": false,
"keepWithNext": false,
"avoidWidowAndOrphan": true,
"shading": {
"backgroundColor": {}
}
}
},
{
"namedStyleType": "HEADING_1",
"textStyle": {
"fontSize": {
"magnitude": 20,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 20,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 6,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_2",
"textStyle": {
"bold": false,
"fontSize": {
"magnitude": 16,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 18,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 6,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_3",
"textStyle": {
"bold": false,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.2627451,
"green": 0.2627451,
"blue": 0.2627451
}
}
},
"fontSize": {
"magnitude": 14,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 16,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_4",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 12,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 14,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_5",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 12,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_6",
"textStyle": {
"italic": true,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 12,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "TITLE",
"textStyle": {
"fontSize": {
"magnitude": 26,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"magnitude": 3,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "SUBTITLE",
"textStyle": {
"italic": false,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 15,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"magnitude": 16,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
}
]
},
"revisionId": "XXXXXXXXXXXXX",
"suggestionsViewMode": "SUGGESTIONS_INLINE",
"documentId": "XXXXXXXXXXXXX"
}
有谁知道如何正确使用 API 来创建具有特定内容的 google 文档?
Method: documents.create
Creates a blank document using the title given in the request. Other fields in the request, including any provided content, are ignored.
如果要创建包含文本的文档,您必须:
- 使用 documents.create 创建文档。
- 使用 documents.batchUpdate 添加内容。
我目前正在尝试使用 Google 文档 API 创建一个 google 文档。 https://developers.google.com/docs/api/reference/rest/v1/documents/create
我尝试使用网站工具并创建一个包含以下正文的文档。
{
"body": {
"content": [
{
"paragraph": {
"elements": [
{
"textRun": {
"content": "This is a test"
}
}
]
}
}
]
},
"title": "Hello"
}
但是 return 不包含单词 "This is a test"。
return JSON 消息
{
"title": "Hello",
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT"
}
}
},
{
"startIndex": 1,
"endIndex": 2,
"paragraph": {
"elements": [
{
"startIndex": 1,
"endIndex": 2,
"textRun": {
"content": "\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT"
}
}
}
]
},
"documentStyle": {
"background": {
"color": {}
},
"pageNumberStart": 1,
"marginTop": {
"magnitude": 72,
"unit": "PT"
},
"marginBottom": {
"magnitude": 72,
"unit": "PT"
},
"marginRight": {
"magnitude": 72,
"unit": "PT"
},
"marginLeft": {
"magnitude": 72,
"unit": "PT"
},
"pageSize": {
"height": {
"magnitude": 841.8897637795277,
"unit": "PT"
},
"width": {
"magnitude": 595.27559055118115,
"unit": "PT"
}
}
},
"namedStyles": {
"styles": [
{
"namedStyleType": "NORMAL_TEXT",
"textStyle": {
"bold": false,
"italic": false,
"underline": false,
"strikethrough": false,
"smallCaps": false,
"backgroundColor": {},
"foregroundColor": {
"color": {
"rgbColor": {}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
},
"baselineOffset": "NONE"
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"alignment": "START",
"lineSpacing": 115,
"direction": "LEFT_TO_RIGHT",
"spacingMode": "COLLAPSE_LISTS",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"unit": "PT"
},
"borderBetween": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderTop": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderBottom": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderLeft": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"borderRight": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
"indentFirstLine": {
"unit": "PT"
},
"indentStart": {
"unit": "PT"
},
"indentEnd": {
"unit": "PT"
},
"keepLinesTogether": false,
"keepWithNext": false,
"avoidWidowAndOrphan": true,
"shading": {
"backgroundColor": {}
}
}
},
{
"namedStyleType": "HEADING_1",
"textStyle": {
"fontSize": {
"magnitude": 20,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 20,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 6,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_2",
"textStyle": {
"bold": false,
"fontSize": {
"magnitude": 16,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 18,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 6,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_3",
"textStyle": {
"bold": false,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.2627451,
"green": 0.2627451,
"blue": 0.2627451
}
}
},
"fontSize": {
"magnitude": 14,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 16,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_4",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 12,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 14,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_5",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 12,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "HEADING_6",
"textStyle": {
"italic": true,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 11,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"magnitude": 12,
"unit": "PT"
},
"spaceBelow": {
"magnitude": 4,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "TITLE",
"textStyle": {
"fontSize": {
"magnitude": 26,
"unit": "PT"
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"magnitude": 3,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
},
{
"namedStyleType": "SUBTITLE",
"textStyle": {
"italic": false,
"foregroundColor": {
"color": {
"rgbColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
}
}
},
"fontSize": {
"magnitude": 15,
"unit": "PT"
},
"weightedFontFamily": {
"fontFamily": "Arial",
"weight": 400
}
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT",
"spaceAbove": {
"unit": "PT"
},
"spaceBelow": {
"magnitude": 16,
"unit": "PT"
},
"keepLinesTogether": true,
"keepWithNext": true
}
}
]
},
"revisionId": "XXXXXXXXXXXXX",
"suggestionsViewMode": "SUGGESTIONS_INLINE",
"documentId": "XXXXXXXXXXXXX"
}
有谁知道如何正确使用 API 来创建具有特定内容的 google 文档?
Method: documents.create
Creates a blank document using the title given in the request. Other fields in the request, including any provided content, are ignored.
如果要创建包含文本的文档,您必须:
- 使用 documents.create 创建文档。
- 使用 documents.batchUpdate 添加内容。