Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tharushaudana/fcm-send-with-oauth2-php
This is the latest way to send FCM messages via REST API.
https://github.com/tharushaudana/fcm-send-with-oauth2-php
cloud-messaging fcm fcm-messaging fcm-push-notification fcmpush firebase oauth2 php rest-api
Last synced: about 3 hours ago
JSON representation
This is the latest way to send FCM messages via REST API.
- Host: GitHub
- URL: https://github.com/tharushaudana/fcm-send-with-oauth2-php
- Owner: tharushaudana
- Created: 2024-06-27T15:43:37.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-28T07:59:52.000Z (5 months ago)
- Last Synced: 2024-06-28T12:13:47.800Z (5 months ago)
- Topics: cloud-messaging, fcm, fcm-messaging, fcm-push-notification, fcmpush, firebase, oauth2, php, rest-api
- Language: PHP
- Homepage:
- Size: 1000 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Firebase Cloud Messaging via REST API using PHP
This repository contains a PHP script to send Firebase Cloud Messages (FCM) via the REST API. It includes both the generation of an OAuth2 access token using a Google service account key and the sending of FCM messages.
## Instructions
1. **Clone the Repository**
```sh
git clone https://github.com/tharushaudana/fcm-send-with-oauth2-php.git
```2. **Edit Service Account Key Path**
In `access_token.php`, replace the placeholder with the path to your Google service account key JSON file:
```php
$creds = file_get_contents('path/to/your/service-account-key.json');
```3. **Edit FCM Data**
In `index.php`, edit the FCM data to suit your needs. Change the `validate_only` parameter to `true` if you only want to validate the request without sending a message:
```php
$firebase_data = [
'validate_only' => false,
'message' => [
'topic' => 'user_4',
'notification' => [
'title' => 'test title',
'body' => 'test body',
],
'android' => [
'collapse_key' => 'type_a',
],
'data' => [
'test' => 'test value'
]
]
];
```4. **Load `index.php` Using a Web Server**
Ensure you are running a web server, then load `index.php` to send the FCM message.
## Generating and Downloading the Google Service Account Key
The screenshots below will help you create and download the Google service account key JSON for your Firebase project:
- ![Screenshot 1](screenshots/01.png)
- ![Screenshot 2](screenshots/02.png)
- ![Screenshot 3](screenshots/03.png)I hope this helps you implement the latest FCM send method via the REST API.