admin管理员组文章数量:1402802
I am trying to send a notification to a group of devices (topic) usin Auth2. So first I tried to send a message to single device, and it worked OK.
Now I want to create the topic. So I use this code that is attached at the bottom, but I get the result:
result= {"error":"Authentication using server key is deprecated. Please use an OAuth2 token instead."}
The access-token is the same as I use for sending one message.
The code:
$topic="{$card_id}_{$type}_{$locale}";
$url = ":batchAdd";
$json=["to" => "/topics/{$topic}", "registration_tokens" => [$fcm_token]];
$result=send_2_FCM($json,$url);
function send_2_FCM($data,$url)
{
require_once('firebase_access_token.php');
$access_token=getAccessToken();
$headers = array(
"Authorization: Bearer $access_token",
"Content-Type: application/json"
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL,$url);
curl_setopt( $ch,CURLOPT_POST,true);
curl_setopt( $ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt( $ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt( $ch,CURLOPT_CAINFO, "cacert.pem");
if ($data)
{
curl_setopt( $ch,CURLOPT_POSTFIELDS,json_encode($data));
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
debug_log("send_2_FCM: result= $result");
if ($result && strpos($result,'"error"')) return 0;
return 1;
}
本文标签: phpFCM Auth2 subscribe to topic erro Authentication usingStack Overflow
版权声明:本文标题:php - FCM Auth2 subscribe to topic erro: Authentication using - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744305329a2599783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论