Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase托管+;云功能&x2B;node.js问题_Node.js_Google Cloud Functions_Firebase Hosting - Fatal编程技术网

Firebase托管+;云功能&x2B;node.js问题

Firebase托管+;云功能&x2B;node.js问题,node.js,google-cloud-functions,firebase-hosting,Node.js,Google Cloud Functions,Firebase Hosting,我将node.js与Firebase托管一起使用,并且还使用了一些函数。 我尝试设置一个基本功能,但根据调试部署发送错误消息: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or o

我将node.js与Firebase托管一起使用,并且还使用了一些函数。 我尝试设置一个基本功能,但根据调试部署发送错误消息:

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}
此外:

函数文件夹中的My index.js如下:

const functions = require('firebase-functions');
const express = require('express');

var admin = require("firebase-admin");

var serviceAccount = require("<<path to file under Functions dir, downloaded from Firebase Console/Settings/Service accounts/Generate new private key>>");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://MYPROJECT.firebaseio.com"
});
    
exports.urbData = functions.https.onCall((data, context) => {
    console.log("SUCCESS");
})
const functions=require('firebase-functions');
const express=require('express');
var admin=require(“firebase admin”);
var servicecomport=require(“”);
admin.initializeApp({
凭证:管理员凭证证书(serviceAccount),
数据库URL:“https://MYPROJECT.firebaseio.com"
});
exports.urbData=functions.https.onCall((数据,上下文)=>{
控制台日志(“成功”);
})
JSON文件如下所示:

{
  "type": "service_account",
  "project_id": "MYPROJECT",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\xxx\n-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-xxxxxxxxxxxxxxx@MYPROJECT.iam.gserviceaccount.com",
  "client_id": "xxx",

"key": "<<API KEY>>",

  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-xxxxxxxxxxxxxxx.iam.gserviceaccount.com"
}
{
“类型”:“服务账户”,
“项目id”:“我的项目”,
“私钥id”:“xxx”,
“私钥”:“开始私钥------\xxx\n------结束私钥------\n”,
“客户端电子邮件”:“firebase adminsdk-xxxxxxxxxxxxxxx@MYPROJECT.iam.gserviceaccount.com",
“客户id”:“xxx”,
“密钥”:“密钥”,
“auth_uri”:https://accounts.google.com/o/oauth2/auth",
“令牌uri”:https://oauth2.googleapis.com/token",
“身份验证提供程序\u x509\u证书\u url”:https://www.googleapis.com/oauth2/v1/certs",
“客户端\u x509\u证书\u url”:https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-xxxxxxxxxxxxxxx.iam.gserviceaccount.com"
}
我已经检查了谷歌云控制台,并且谷歌云功能已经启用到API密钥。(我还仔细检查了启用firebase init的函数。)

我不确定这是否重要,但实际上我在同一个项目中有另一个应用程序(Android)


有人知道更正此错误的解决方案吗?

Hi@SzB此错误通常表示您没有正确设置部署的服务帐户,或者此服务帐户没有适当的权限。考虑到这一点,你能继续关注本教程并检查它是否对你有帮助吗?非常感谢@gso_gabriel,我已经仔细检查了教程的过程,一切似乎都很好,尽管网站仍然给出了提到的错误。还有其他想法吗?您好@SzB如果一切都按照教程中的设置,我建议您直接联系,这样他们就可以直接帮助您解决这个问题。最后,我发现了我之前犯的错误。这是我设置的一个服务,所以我不得不取消设置,只有有效的服务。”函数:config:unset SERVICE'命令完成了这一任务。
{
  "type": "service_account",
  "project_id": "MYPROJECT",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\xxx\n-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-xxxxxxxxxxxxxxx@MYPROJECT.iam.gserviceaccount.com",
  "client_id": "xxx",

"key": "<<API KEY>>",

  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-xxxxxxxxxxxxxxx.iam.gserviceaccount.com"
}