我正在尝试编写一个访问我的bigquery数据的google云功能。但是,当我运行它时出现错误。如果我在本地模拟器下运行,它可以正常工作,但在部署时则不行。
我的package.json:
{
"dependencies": {
"@google-cloud/bigquery": "^0.9.6"
}
}
index.js
var BigQuery = require('@google-cloud/bigquery');
exports.hello = function hello(req, res) {
var bigQuery = BigQuery({ projectId: 'influence-ranking' });
bigQuery.query({
query: 'SELECT label from `influence-ranking.wikidata.labels` LIMIT 1',
useLegacySql: false
}).then(function () {
return res.status(200).send('hello');
}).catch(function (error) {
return res.status(500).json(error);
});
};
我部署了这个功能:
$ gcloud beta functions deploy hello --stage-bucket influence-ranking-web --trigger-http --project influence-ranking
Copying file:///tmp/tmpwR3Sza/fun.zip [Content-Type=application/zip]...
/ [1 files][ 7.3 KiB/ 7.3 KiB]
Operation completed over 1 objects/7.3 KiB.
Deploying function (may take a while - up to 2 minutes)...done.
availableMemoryMb: 256
entryPoint: hello
httpsTrigger:
url: https://us-central1-influence-ranking.cloudfunctions.net/hello
labels:
deployment-tool: cli-gcloud
latestOperation: operations/aW5mbHVlbmNlLXJhbmtpbmcvdXMtY2VudHJhbDEvaGVsbG8vdHJoV1pjeWlnSkk
name: projects/influence-ranking/locations/us-central1/functions/hello
serviceAccount: tfc7c97f9c5ac6052-tp@appspot.gserviceaccount.com
sourceArchiveUrl: gs://influence-ranking-web/us-central1-hello-poucdhlbhptc.zip
status: READY
timeout: 60s
updateTime: '2017-09-20T18:42:22Z'
versionId: '15'
$ curl https://us-central1-influence-ranking.cloudfunctions.net/hello
{"code":403,"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","extendedHelp":"https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993"}],"message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}
错误消息中的链接显示错误:
The API "bigquery.googleapis.com" doesn't exist or you don't have permission to access it
看起来项目参数与Google云端控制台中为我的项目列出的项目编号不对应。所以它让我觉得我不知何故得到了针对错误项目的请求,但我无法弄清楚如何。
答案 0 :(得分:4)
我的Google云端功能帐户中出现了一些问题。
我结束了:
现在它有效。
重要的是,部署的输出现在说:
serviceAccount: influence-ranking@appspot.gserviceaccount.com
所以它使用的是正确的服务帐户。