首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法创建包含内容的google文档

无法创建包含内容的google文档
EN

Stack Overflow用户
提问于 2019-11-16 05:46:54
回答 1查看 127关注 0票数 0

我目前正在尝试用创建一个google文档。https://developers.google.com/docs/api/reference/rest/v1/documents/create

我尝试使用网站工具,并创建一个文件与以下主体。

代码语言:javascript
复制
{
  "body": {
    "content": [
      {
        "paragraph": {
          "elements": [
            {
              "textRun": {
                "content": "This is a test"
              }
            }
          ]
        }
      }
    ]
  },
  "title": "Hello"
}

但是它返回的内容并不包含“这是一个测试”这个词。

返回JSON消息

代码语言:javascript
复制
{
  "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文档吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-19 08:46:02

来自正式文件

方法: documents.create 使用请求中指定的标题创建空白文档。请求中的其他字段,包括任何提供的内容,都将被忽略。

如果要创建文本文档,则必须:

  1. 使用documents.create创建文档。
  2. 使用documents.batchUpdate向其添加内容。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58887969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档