【发布时间】:2018-12-02 02:40:57
【问题描述】:
我有一个使用 fcm 来通知的应用程序,当我通过控制台发送消息时一切正常,但是当我尝试通过 php(curl post)或 postman(firefox 扩展)发送时,我得到了一个身份验证错误(即使使用键)
string(304) "{ "error": { "code": 401, "message": "请求缺少所需的身份验证凭据。预期的 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。见https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } } "
我从 firebase 项目控制台获得了密钥 我的php代码是
public function send_FCM(){
// Method - 1
$fcmUrl = 'https://fcm.googleapis.com/v1/projects/anal.........719/messages:send';
$notification = array(
"to"=>"/topic/cidade396",
"notification"=>array(
"body"=>"test 123"
)
);
$headers = [
'Authorization: key=AIz.........9KWwy5BisxXYbA8',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
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_POSTFIELDS, json_encode($notification));
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
return true;
} 有谁知道我该如何解决这个问题?
【问题讨论】:
标签: php firebase curl google-cloud-messaging firebase-cloud-messaging