简体   繁体   中英

Google Sheets API v4 share

My Webapp is creating, writing and reading google sheets perfectly.

But I cannot find anything in the documentation about how to share the newly created document. I need to be able to give editing access to other individuals.

我相信您需要使用Drive API (而不是 Sheets API)来完成此操作。

You can create permission and can share with any other user. Below is the code snippet.

 var body = {
      'type': 'user',
      'role': 'reader',// reader/writer/organzier
      'emailAddress': 'xyz@gmail.com'
    };

    var drive=google.drive({version: 'v3',auth});

    drive.permissions.create({
      'fileId': "SheetId",  //sheetID returned from create sheet response
      'resource': body,
    }, function(err, response) {if (err) {
      console.error('error-------', err);
      return;
      } else{
        console.log(JSON.parse(JSON.stringify(response))) ;
      }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM