gpt4 book ai didi

Firebase 消息传递,无法确定消息传递的项目 ID

转载 作者:行者123 更新时间:2023-12-03 19:30:15 26 4
gpt4 key购买 nike

如何初始化我的应用程序以进行消息传递?我不断收到错误

“错误:无法确定消息传递的项目 ID。使用服务帐户凭据初始化 SDK,或将项目 ID 设置为应用程序选项。或者设置 GOOGLE_CLOUD_PROJECT 环境变量。”

当我尝试调用 messaging

const functions = require("firebase-functions");
const admin = require("firebase-admin");

const config = {
type: "service_account",
project_id: "xxx",
private_key_id: "xxx",
private_key:
"-----BEGIN PRIVATE KEY-----xxx-----END PRIVATE KEY-----\n",
client_email:
"firebase-adminsdk-8dd2o@pushmessage-bd1eb.iam.gserviceaccount.com",
client_id: "107357357611247077666",
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-8dd2o%40pushmessage-bd1eb.iam.gserviceaccount.com"
};

admin.initializeApp({
config
});

const db = admin.firestore();
const messaging = admin.messaging();

const message = {
data: { title: "Testing", body: "Test" },
tokens: registrationTokens
};

messaging.sendMulticast(message).then(response => {
console.log(response.successCount + " messages were sent successfully");
});

最佳答案

这些行没有意义:

const db = admin.firestore(functions.config().firebase);
const messaging = admin.messaging(functions.config().firebase);

通过将该参数传递给 admin.firestore(),我不确定您打算做什么和 admin.messaging() .

如果它在 Cloud Functions 中运行,也许您打算像这样初始化 Admin SDK:
const admin = admin.initializeApp();

并像这样使用它:
const db = admin.firestore();
const messaging = admin.messaging();

关于Firebase 消息传递,无法确定消息传递的项目 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55538696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com