Comments (4)
Ohhhhh i'm so sorry for inconvenience !!! I should have to see myself :(
from php-firebase-cloud-messaging.
Can you paste an example of the code you are using?
from php-firebase-cloud-messaging.
use sngrl\PhpFirebaseCloudMessaging\Client;
use sngrl\PhpFirebaseCloudMessaging\Message;
use sngrl\PhpFirebaseCloudMessaging\Notification;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;
$defaults = array(
"title" => "Title",
"message" => "Message",
"priority" => "normal",
"device_token" => "<my_device_token>",
);
extract($defaults);
require_once WP_CONTENT_DIR . "/../../vendor/autoload.php";
$client = new Client();
$client->setApiKey("server_key");
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
$message = new Message();
$message->setPriority($priority);
$message->addRecipient(new Device($device_token));
$message->setNotification(new Notification($title, $message));
$message->setData(array(
"title" => $title,
"body" => $message,
));
try {
$response = $client->send($message);
} catch (Exception $e) {
echo $e->getMessage();
}
from php-firebase-cloud-messaging.
When extracting the $defaults
array here:
$defaults = array(
"title" => "Title",
"message" => "Message",
"priority" => "normal",
"device_token" => "<my_device_token>",
);
extract($defaults);
You are creating a $message
variable for the body of the notification, but then you create a new $message
variable and give the value of the Message
object:
$message = new Message();
Then when you set the data of the Notification you pass as body of notification the new Message object:
$message->setData(array(
"title" => $title,
"body" => $message,
));
This causes a malformed JSON when the HTTP Client encodes it before doing the request.
Instead a valid code would be this:
use sngrl\PhpFirebaseCloudMessaging\Client;
use sngrl\PhpFirebaseCloudMessaging\Message;
use sngrl\PhpFirebaseCloudMessaging\Notification;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;
$defaults = array(
"title" => "Title",
"body_message" => "Message",
"priority" => "normal",
"device_token" => "<my_device_token>",
);
extract($defaults);
require_once WP_CONTENT_DIR . "/../../vendor/autoload.php";
$client = new Client();
$client->setApiKey("server_key");
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
$message = new Message();
$message->setPriority($priority);
$message->addRecipient(new Device($device_token));
$message->setNotification(new Notification($title, $body_message));
$message->setData(array(
"title" => $title,
"body" => $body_message,
));
try {
$response = $client->send($message);
} catch (Exception $e) {
echo $e->getMessage();
}
from php-firebase-cloud-messaging.
Related Issues (20)
- Cannot install php-firebase-cloud-messaging? HOT 1
- time_to_live - how do you set it? HOT 1
- Token Suscripcion not response
- Trait 'sngrl\PhpFirebaseCloudMessaging\Client' not found HOT 1
- setSound is not working HOT 2
- How can I add custom cURL options? HOT 2
- Uncaught Error: Call to a member function post() on null in Client.php 62 HOT 8
- IOS Mutable Content
- how can I unsubscribeFromTopic HOT 8
- How to send an Image through notification or data message type? HOT 1
- Stability
- Could not find a version of package matching your minimum-stability (stable). HOT 1
- Background android notification HOT 3
- Token Infos
- Android sound Android O+ HOT 1
- status received success but not received notification on mobile device HOT 1
- Can i schedule and cancel a scheduled push notification?
- how to use fcm_options.link ?
- Deprecated: Return type Message::jsonSerialize() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-firebase-cloud-messaging.