我测试了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
答案 0 :(得分:0)
$headers = array (
'Authorization: key =' . server_key,
'Content-Type:application/json'
);
你应该使server_key成为像$ server_key
这样的变量