我知道我以前遇到过这个,但我似乎再也找不到它了。 是否存在允许在不使用浏览器的情况下检索 Google API 访问 token 的 Node.js 模块? 我想在 headless 服务器上向 Google API 发出经过身份验证的请求。然而,我找到的模块都需要浏览器。 是否存在一个模块可以完全在服务器上处理所有这些?
最佳答案
如果您希望服务器代表自己行事(即不代表登录到您的应用程序的用户访问 Google API),则可以通过在 Google 开发者控制台 (google oauth2 how to get private key for service account) 中创建服务帐户来实现并使用 Google API node.js 客户端 (https://github.com/google/google-api-nodejs-client/)。
请参阅以下示例,了解如何从 Node.js 应用程序使用 Google Cloud Datastore - 身份验证原则与其他 Google API 相同: https://developers.google.com/datastore/docs/getstarted/start_nodejs/
关于javascript - 用于 headless 检索访问 token 的 Node.js oauth2 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20976203/