简体   繁体   English

如何使用Node.js在远程服务器上使用对Google Sheets API进行身份验证的用户?

[英]How to use authenticate a user for google sheets api on a remote server using Node.js?

I am working with Google sheets and node.js and I am able to authorize a user locally and get auth data using cmd using this tutorial https://developers.google.com/sheets/api/quickstart/nodejs but cant authorize it on a remote server like Heroku so I have found an example https://codelabs.developers.google.com/codelabs/sheets-api/#4 but can't really grasp how to implement it in this example https://developers.google.com/sheets/api/quickstart/nodejs . 我正在使用Google表格和node.js,并且能够使用本教程https://developers.google.com/sheets/api/quickstart/nodejs使用cmd在本地授权用户并获取身份验证数据,但无法在像Heroku这样的远程服务器,所以我找到了一个示例https://codelabs.developers.google.com/codelabs/sheets-api/#4,但是在这个示例https:// developers中并不能真正掌握如何实现它。 google.com/sheets/api/quickstart/nodejs

Thanks in Advance!! 提前致谢!!

Depending on your requirements and architecture, it may make sense to write to the spreadsheet using a service account . 根据您的要求和体系结构,使用服务帐户写入电子表格可能很有意义。 Here is my code for doing that from NodeJS . 这是我从NodeJS执行此操作的代码

Advantages of service accounts: 服务帐户的优势:

  • You don't have to do the OAuth dance (less code, fewer steps for the user). 您不必进行OAuth跳舞(更少的代码,更少的用户步骤)。
  • Your code can write to the spreadsheet even when no user has granted OAuth access. 即使没有用户授予OAuth访问权限,您的代码也可以写入电子表格。

Disadvantage: 坏处:

  • It's hard to enforce different access for different users, as all writes happen with whatever access you have granted to the service account. 很难为不同的用户强制执行不同的访问,因为所有写操作都与您授予服务帐户的访问权限有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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