Google Docs API-文档显示了如何' dump' DOC作为JSON进行故障排除,但JSON返回与提出请求的JSON不同

发布于 2025-01-23 05:51:27 字数 2317 浏览 0 评论 0原文

我正在使用Google Docs API编写Google文档,并且发现有一个JSON“转储”功能可以帮助您了解Google文档的结构。

唯一的问题是,JSON转储与用于实际编写DOC的JSON不同。

例如,这是我发现有关JSON转储的地方:

https:// https:// https:// developers.google.com/docs/api/samples/output-json

截断的JSON示例看起来像这样:

{
    "body": {
        "content": [
            {
                "endIndex": 1, 
                "sectionBreak": {
                    "sectionStyle": {
                        "columnSeparatorStyle": "NONE", 
                        "contentDirection": "LEFT_TO_RIGHT"
                    }
                }
            }, 
            {
                "endIndex": 75, 
                "paragraph": {
                    "elements": [
                        {
                            "endIndex": 75, 
                            "startIndex": 1, 
                            "textRun": {
                                "content": "This is an ordinary paragraph. It is the first paragraph of the document.\n", 
                                "textStyle": {}
                            }
                        }
                    ], 
                    "paragraphStyle": {
                        "direction": "LEFT_TO_RIGHT", 
                        "namedStyleType": "NORMAL_TEXT"
                    }
                }, 
                "startIndex": 1
            }, 

这是用于向您的文档提出更新请求的文档:

https://develoveers.google.google.com/docs/api/papi/reference/reest/rest/rest/rest/v1/documents/documents/request

基本上我看到的是,两者具有一些共同的一般结构,但是实际编写JSON的表示法是不同的。

例如,这是一个如何写入文档的示例:

      const updateObject = {
        documentId: 'documentID',
        resource: {
          requests: [ {
            insertText: {
              text: 'hello world',
              location: {
                index: 1,
              },
            },
          } ],
        },
      };

我希望有一种方法可以像转储结构化的方式一样编写JSON,然后通过该格式传递以创建新文档。否则,我将不得不乏味地翻译从一种格式到另一种格式(还有很多),

有人对此有任何建议吗?也许我缺少一些东西。谢谢!

I'm writing a google doc using the google docs api, and I found that there is a json 'dump' feature that helps you understand the structure of your google doc.

The only problem is, the JSON dump is different than the JSON used to actually write the doc.

For example, this is where I found out about the JSON dump:

https://developers.google.com/docs/api/samples/output-json

The truncated JSON example looks like this:

{
    "body": {
        "content": [
            {
                "endIndex": 1, 
                "sectionBreak": {
                    "sectionStyle": {
                        "columnSeparatorStyle": "NONE", 
                        "contentDirection": "LEFT_TO_RIGHT"
                    }
                }
            }, 
            {
                "endIndex": 75, 
                "paragraph": {
                    "elements": [
                        {
                            "endIndex": 75, 
                            "startIndex": 1, 
                            "textRun": {
                                "content": "This is an ordinary paragraph. It is the first paragraph of the document.\n", 
                                "textStyle": {}
                            }
                        }
                    ], 
                    "paragraphStyle": {
                        "direction": "LEFT_TO_RIGHT", 
                        "namedStyleType": "NORMAL_TEXT"
                    }
                }, 
                "startIndex": 1
            }, 

And here is documentation for making update requests to your document:

https://developers.google.com/docs/api/reference/rest/v1/documents/request

Basically what I'm seeing is that the two have some general structures in common, but the notation for actually writing the JSON is different.

For instance, here's an example of how to write to the document:

      const updateObject = {
        documentId: 'documentID',
        resource: {
          requests: [ {
            insertText: {
              text: 'hello world',
              location: {
                index: 1,
              },
            },
          } ],
        },
      };

I'm hoping there is a way I can write the json in the same way that the dump is structured, and then pass that format through to create new documents. Otherwise I'm going to have to tediously translate everything from one format to the other (and there's a lot),

Does anyone have any advice on this? Maybe there is something I'm missing. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2025-01-30 05:51:27

它似乎是故意的。该示例中的JSON转储匹配 document 对象。当您通过 document.create API。不幸的是,几乎所有的字段都是仅输出的。我试图将body从样本插入API中,尽管它并没有失败,但它也忽略了输入,而只是创建了一个基本文档。

同时,您发现要发送更新请求的batchupdate方法似乎都集中在特定的更改上,并且没有一个document对象。我认为您最好的选择是跟进您发现的功能请求,毕竟,文档API仍在V1中考虑。

It appears to be intended. The JSON dump in the example matches the Document object. You can also find this same structure returned when you create a document via thedocuments.create API. Unfortunately, pretty much all of the fields are output-only. I tried to plug in the body from the sample into the API, and while it didn't fail, it also ignored the input and just created a basic document.

Meanwhile, the batchUpdate methods that you found to send update requests all seem focused on specific changes and none of them take a Document object. I think your best bet would be to follow up the feature request that you found, the Docs API is still considered in v1 after all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文