我遇到下一个错误:
Kreait \ Firebase \ Exception \ Messaging \ InvalidMessage
客户端错误:POST https://fcm.googleapis.com/v1/projects/wesig-c9298/messages:send
导致了400 Bad Request
响应:
{
“错误”:{
“代码”:400,
“ message”:“请求包含无效的参数。”,
“状态”:“ INVALID_ARGUMENT”(已截断...)
这是我的代码:
$serviceAccount = Firebase\ServiceAccount::fromJsonFile(__DIR__."/apikey.json");
$firebase = (new Firebase\Factory())
->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 = Firebase\Messaging\MessageToRegistrationToken::fromArray([
'token' => $token,
'notification' => $notification, // optional
'data' => $data, // optional
]);
$messaging->send($message);
我认为该错误是在令牌内,但我找不到解决方法。
答案 0 :(得分:0)
在Level 4 selector that currently cannot be used in stylesheets中,看来TokenGenerator
产生了一个认证令牌。那不是你想要的。消息中的token
是通过调用客户端SDK获得的设备注册令牌。例如,在Android上为the documentation。