| 问题 我正在尝试通过 JWT 客户端使用 Google 的 node.js 客户端库生成访问令牌。
 
 下面是我的代码片段:
 
 复制代码var google = require("googleapis");
// Load the service account key JSON file.
var serviceAccount = require("path/to/serviceAccountKey.json");
// Specify the required scope.
var scopes = [
  "https://www.googleapis.com/auth/firebase"
];
// Authenticate a JWT client with the service account.
var jwtClient = new google.auth.JWT(
  serviceAccount.client_email,
  null,
  serviceAccount.private_key,
  scopes
);
// Use the JWT client to generate an access token.
jwtClient.authorize(function(error, tokens) {
  if (error) {
    console.log("Error making request to generate access token:", error);
  } else if (tokens.access_token === null) {
    console.log("Provided service account does not have permission to generate access tokens");
  } else {
    var accessToken = tokens.access_token;
    // Include the access token in the Authorization header.
  }
});
但我不断收到此错误消息:
 
 有谁知道是什么原因?
 
 回答
 从 26.0.0 node.js 客户端版本开始,该库似乎正在使用命名导入。当我更改代码时,代码工作正常
 
 var google = require("googleapis");
 
 到达
 
 var {google} = 要求(“googleapis”);
 
 所以这看起来像是 Firebase 中的一个文档错误。
 
 
 
 
 |