`400错误请求`Firebase通知



我得到下一个错误:

Kreit\Firebase\Exception \ Messaging \ InvalidMessage客户端错误:POST https://fcm.googleapis.com/v1/projects/wesig-c9298/messages:send导致400 Bad Request响应:{"错误":{"代码":400,"message":"请求包含无效参数。","status":"INVALID_ARGUMENT"(截断…(

这是我的代码:

$serviceAccount = FirebaseServiceAccount::fromJsonFile(__DIR__."/apikey.json");
$firebase = (new FirebaseFactory())
->withServiceAccount($serviceAccount)
->create();
$messaging = $firebase->getMessaging();
try {
$generator = new TokenGenerator('AAAALLHVwdc:APA91bFOI1eaWOQTlLq7oezE8E5yWqIb584xDSA10ylTYuIS4Ys9A0qQaqiBSp7A0jRT9_tsaCrNP59Wm-pzD_9wCO4uuxnwD1dmyc5_dF4i9iNHi1TLOxrwmvc-WMPG6K5YFYs5knvla2M_oV7WOKRToawWRNch3g');
$token = $generator
->setData(array('uid' => $user->attributes['uid']))
->create();
} catch (TokenException $e) {
echo "Error: ".$e->getMessage();
}
$notification = [
'title' => "Titulo",
'body' => "Cuerpo"
];
$data = [
'user' => 'yay',
'fecha' => date('d-m-Y')
];
$message = FirebaseMessagingMessageToRegistrationToken::fromArray([
'token' => $token,
'notification' => $notification, // optional
'data' => $data, // optional
]);
$messaging->send($message);

我认为错误在令牌中,但我就是找不到修复它的方法。

从文档中看,TokenGenerator生成了一个auth令牌。这不是你想要的。消息中的token是从对客户端SDK的调用中获得的设备注册令牌。例如,在Android上,它是FirebaseInstanceId.getInstance((.getInstanceId((.

相关内容

  • 没有找到相关文章

最新更新