【发布时间】:2016-12-23 22:58:56
【问题描述】:
我正在测试 firebase 通知,因为我的旧项目已集成到 GCM,但现在我也在使用 firebase 数据库。
我正在尝试执行一个 php 脚本,以便向我的一台设备发送通知。我能够获得TokenID,并且我能够从 Firebase 控制台向此令牌发送通知,但是当我使用 PHP 脚本时,出现以下错误:
传递的(旧版)服务器密钥无效或发件人无权执行请求。
这是我的脚本:
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AAAXXXXXX";
$key = "c43xxxxxxxxx";
$headers = array (
'Authorization: key =' . server_key,
'Content-Type:application/json'
);
$fields = array('to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl_session, CURLOPT_CUSTOMREQUEST, "POST");
$result = curl_exec($curl_session);
curl_close($curl_session);
echo $result;
我从以下位置获取 api 密钥:
Firebase console > gear icon > proyect configuration > Cloud messaging
【问题讨论】:
-
“授权”怎么拼写?
-
PHP 中变量的符号是什么?
-
是的“Autorization was wrong”,我改为“Authorization”,现在我收到此错误 /////Invalid (legacy) Server-key Delivered or Sender is not authorized to perform request .
-
您使用的是服务器密钥还是旧服务器密钥?
-
服务器键,我都试过了,结果一样
标签: php android firebase-cloud-messaging