Using Firebase to push notification from WordPress
-
I am trying to push a notification from a plugin using firebase so that the notification is received by the android app.
I have the API key from google but don’t know how to get the device token so that I can push notification using CURL.
This is a post from stackoverflow I have been following but stuck in device token. How can I get it?This what the link mentioned above has recommended:
<?php $message = 'ojlaasdasdasd'; $title = 'ojla'; $path_to_fcm = 'https://fcm.googleapis.com/fcm/send'; $server_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5LnDZO2BpC2aoPMshfKwRbJAJfZL8C33qRxxxxxxxxxxxxL6'; $key = 'eqnlxIQ1SWA:APA91bGf1COAZamVzT4onl66_lEdE1nWfY7rIADcnt9gtNYnw7iWTwa7AYPYTHESFholkZ89ydCQS3QeL-lCIuiWTXiqoDREO0xhNdEYboPvqg8QsBYkrQVRlrCLewC4N-hHUja1NG4f'; $headers = array( 'Authorization:key=' .$server_key, 'Content-Type: application/json'); $fields = array ( 'to' => $key, 'notification' => array('title' => $title,'body' => $message) ); $payload = json_encode($fields); $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, '$path_to_fcm' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt( $ch,CURLOPT_POSTFIELDS, $payload); $result = curl_exec($ch); echo $result; curl_close($ch); ?>
Any help on this would be highly appreciated.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Using Firebase to push notification from WordPress’ is closed to new replies.