I can send push notifications with the new B4J sending tool and these messages are received by my B4X receiver app. So the transformation to the Firebase Cloud Messaging API (v1) including the creation of an access token with the private key (downloaded under tab "service accounts") works.
But how can I "produce" this access token within a php script, which I use for sending push notifications?
But how can I "produce" this access token within a php script, which I use for sending push notifications?
php script:
//Code to catch the accessToken????
$url = 'https://fcm.googleapis.com/v1/projects/my_project_id/messages:send';
$data = array
(
'data_text' => 'You cant always get what you want',
'data_sender' => 'Sir Mick',
'data_senddate' => 'Sept. 21th, 2024',
);
$message = (
'message' => (
'topic' => $'greatExpectations',
'data' => $data,
'android' => ('priority' => 'high'),
),
);
$headers = array
(
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json'
);
$ch = curl_init(); // Open connection
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $message ) );
$result = curl_exec($ch); // Execute post
curl_close($ch); // Close connection