Guest User

Untitled

a guest
Aug 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. $serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google.json');
  2.  
  3. $firebase = (new Factory)
  4. ->withServiceAccount($serviceAccount)
  5. // The following line is optional if the project id in your credentials file
  6. // is identical to the subdomain of your Firebase project. If you need it,
  7. // make sure to replace the URL with the URL of your project.
  8. //->withDatabaseUri('https://my-project.firebaseio.com')
  9. ->create();
  10.  
  11. $messaging = $firebase->getMessaging();
  12.  
  13. $deviceToken = 'token';
  14.  
  15. $notification = Notification::create("test", "body");
  16. $data = [
  17. 'first_key' => 'First Value',
  18. 'second_key' => 'Second Value',
  19. ];
  20.  
  21. $message = CloudMessage::withTarget('token', $deviceToken)
  22. ->withNotification($notification) // optional
  23. ->withData($data);
  24.  
  25. // error here
  26. // 404 Client error: `POST https://fcm.googleapis.com/v1/projects/projectid/messages:send` resulted in a `404 Not Found
  27. $messaging->send($message);
Add Comment
Please, Sign In to add comment