简体   繁体   English

我无法从我的 node.js firebase 函数 index.js 文件中验证大查询

[英]Im failing to authenticate Big query from my node.js firebase functions index.js file

I am using the big query API in my firebase functions index.js file, but I keep getting an internal server error when initializing the Big query instance, my first attempt was to include my service account key file in the functions directory and my code is below我在我的 firebase 函数 index.js 文件中使用了大查询 API,但是在初始化大查询实例时我不断收到内部服务器错误,我的第一次尝试是将我的服务帐户密钥文件包含在函数目录中,我的代码是以下

const functions = require("firebase-functions");
const express = require('express');
const cors = require('cors')({ origin: true });

const app = express();
app.use(cors);
app.use(express.json());



exports.api = functions.https.onRequest(app);


app.post('/create_table', (req, res) => {

  'use strict';

  const { BigQuery } = require('@google-cloud/bigquery');
  const options = {
    keyFilename: 'gamelot-c057c-837d4660ae39.json',
    projectId: 'gamelot-c057c',
  };
  const bigquery = new BigQuery(options);

this is the line causing the error这是导致错误的行

const { BigQuery } = require('@google-cloud/bigquery');
      const options = {
        keyFilename: 'gamelot-c057c-837d4660ae39.json',
        projectId: 'gamelot-c057c',
      };
      const bigquery = new BigQuery(options);

how can I solve this?我该如何解决这个问题?

If you are using Cloud Functions for Firebase (ie Cloud Functions deployed via the Firebase CLI), you should not pass any options when creating the BigQuery client.如果您使用 Cloud Functions for Firebase(即通过 Firebase CLI 部署的 Cloud Functions),则在创建 BigQuery 客户端时不应传递任何选项。 Just do as follows:只需执行以下操作:

const { BigQuery } = require('@google-cloud/bigquery');
const bigquery = new BigQuery();

As a matter of fact, Cloud Functions for Firebase use the App Engine default service account, ie {project-id}@appspot.gserviceaccount.com , which has an Editor role , which, by default, contains permissions to interact with BigQuery.事实上,Cloud Functions for Firebase 使用 App Engine 默认服务帐户,即{project-id}@appspot.gserviceaccount.com ,它具有 Editor角色,默认情况下包含与 BigQuery 交互的权限。

You can check here if the Editor "basic" role has the desired permissions.您可以在此处检查“编辑器”“基本”角色是否具有所需的权限。

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

相关问题 无法使用node.js向MongoDB进行身份验证 - Failing to authenticate with MongoDB using node.js 503将node.js部署从server.js切换到index.js(初学者)时出错 - 503 Error when switching node.js deployment from server.js to index.js (beginner) 如何在用 Node.js 编写的 index.js 中调用 function - How to invoke a function in index.js written in Node.js 来自index.js的单元测试功能 - Unit testing functions from index.js 错误:文件 index.js 定义的 Node.js 模块应该导出名为 xxxx 的函数 - Error: Node.js module defined by file index.js is expected to export function named xxxx 如何将index.js中的json对象发送到node.js中的html - how to send a json object from index.js to html in node.js 如何将 lib.js 文件中的 Discord.js 函数调用到 index.js 中? - How can I call Discord.js functions from a lib.js file into index.js? 如何让 Firebase 函数从另一个目录中找到 index.js? - How to let Firebase functions find index.js from another directory? 如何让 $node index.js 在我的命令行中运行 index.js? - How can I get $node index.js to run index.js in my command line? ./node_modules/firebase/index.js 错误:ENOENT:没有这样的文件或目录 - ./node_modules/firebase/index.js Error: ENOENT: no such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM