I\'m trying FCM for the first time, so just using their sample code. In fact I\'m even sending their sample messages. The following code, which is straight from the document
I had "
in my strings in my json, I changed it to '
and it fixed the problem!
$response = $client->post(
'https://fcm.googleapis.com/v1/projects/xxx/messages:send',[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token['access_token'],
],
GuzzleHttp\RequestOptions::JSON => [
"message" => [
"token" => "dflhjldkjhflksfshklsf",
"notification" => [
"title" => "FCM Message",
"body" => "This is an FCM notification message!"
]
]
]
]);
to:
$response = $client->post(
'https://fcm.googleapis.com/v1/projects/xxx/messages:send',[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token['access_token'],
],
GuzzleHttp\RequestOptions::JSON => [
'message' => [
'token' => 'dflhjldkjhflksfshklsf',
'notification' => [
'title' => 'FCM Message',
'body' => 'This is an FCM notification message!'
]
]
]
]);
Hope it helps!
As Carlos Fernandez Sanz pointed out, one cause for this is that the client and server are connected to different firebase projects. Project name appears in the google-services.json
file on the client and in the credentials json on the server.