我将node.js与Firebase Hosting一起使用,并且Functions也一起使用。 我尝试根据调试设置一个基本功能,但部署发送错误消息:
{
"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"
}
}
也:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
</Message>
<StringToSign>
GET 1603621088 /gcf-upload-us-central1-9fe5e3ed-4073-4e5c-a9ef-a8ad975ad259/0d0b6145-1eb5-4dad-b5cb-a550dcd968a0.zip
</StringToSign>
</Error>
我在函数文件夹中的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");
})
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"
}
我已经检查了Google Cloud Console,并且对API密钥启用了Google Cloud Functions。 (我还仔细检查了启用了firebase init的功能。)
我不确定是否很重要,但是实际上我在同一项目中有另一个应用程序(Android)。
有人知道解决错误的方法吗?