Im using Kreait for sending my firebase push notifications. Ive successfully implemented it but eveytime I try to send the request I get a 404 url does not exist error (Client error: POST https://fcm.googleapis.com/v1/projects/project-id/messages:send
resulted in a `404 Not Found). I have my google authentication json file in the same directory as my php files.
Code:
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
// The following line is optional if the project id in your credentials file
// is identical to the subdomain of your Firebase project. If you need it,
// make sure to replace the URL with the URL of your project.
//->withDatabaseUri('https://my-project.firebaseio.com')
->create();
$messaging = $firebase->getMessaging();
$deviceToken = 'token';
$notification = Notification::create("test", "body");
$data = [
'first_key' => 'First Value',
'second_key' => 'Second Value',
];
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification) // optional
->withData($data);
// error here
// 404 Client error: `POST https://fcm.googleapis.com/v1/projects/projectid/messages:send` resulted in a `404 Not Found
$messaging->send($message);
use ->withDatabaseUri('https://INSERT_YOUR_PROJECT_ID_HERE.firebaseio.com')
... while it appears, that most likely that __DIR__.'/google.json'
(which is usually called google-services.json
) does not exist, therefore the project URL will be unknown. in every case, that projectid
in the URL has to be replaced with the actual project_id
... maybe check the existence of that file with if(! file_exists(__DIR__.'/google.json')) {die('config absent.');}
?
What is the cause of this problem? I have also encountered it. Can it be solved