Create or Open native Google documents using GoogleDriveApi

微笑、不失礼 提交于 2019-12-04 20:09:48

It's not currently possible to read or edit the contents of Google Documents, Spreadsheets or Presentation files. They files are of a special type that don't have standard binary content, so you can't read and write from them in the same way you can from other files.

You can, however, interact with the metadata of existing files.

Sorry for the confusion, we should update the behavior so that its clear that its not possible.

Updating Google Docs with HTML is simple. Just make an api request with html-formatted text in the body (html tag is required) and content-type to be google docs, then your created/updated file will be available to the user as a Google Doc with all the formatting options.

           request({
             uri: 'https://www.googleapis.com/upload/drive/v2/files/'+fileId,
             method: 'PUT',
             qs: {
               uploadType: 'media'
             },
             form: '<html> Hello <b>World!</b> </html>',
             headers: {
               'Content-Type': 'application/vnd.google-apps.document',
               'Authorization': 'Bearer ' + access_token
             }},  function (error, response, body){


           })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!