gpt4 book ai didi

php - Android FCM 推送通知使用的 key 在哪里?

转载 作者:行者123 更新时间:2023-12-05 05:40:12 25 4
gpt4 key购买 nike

我安装了 firebase,如果我通过 firebase 控制台手动发送推送通知,我的应用程序会收到它。

我正在尝试使用 php 脚本向 FCM 发送通知。

问题是我不知道应该使用什么 key ?

如果我在 firebase 控制台中使用那个,我会得到这个 401 错误:“无效 key ”

enter image description here

如果我使用 Api & Services 中的那个,我会得到这个 401 错误“PROJECT_NOT_PERMITTED”

enter image description here

这是我正在使用的 php 脚本:

$server_key = ""
$token = ""
$title = ""
$body = ""
$curl = curl_init();
$authKey = "key=" . $server_key;
$registration_ids = $token;
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{
"registration_ids": ' . $registration_ids . ',
"notification": {
"title": ' . $title . ',
"body": ' . $body . '
}
}',
CURLOPT_HTTPHEADER => array(
"Authorization: " . $authKey,
"Content-Type: application/json",
"cache-control: no-cache"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo "no error: " . $response;
}

当然,它在 else 语句中打印我的 echo:

“没有错误:401 ...”

有人可以帮助我吗?

最佳答案

尝试在 Firebase 控制台项目设置中启用 Cloud Messaging API(旧版)。

关于php - Android FCM 推送通知使用的 key 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72452847/

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