Comments (3)
Unfortunately, I am not able to reproduce the issue, I tried it by performing the following steps:
$ composer create-project symfony/skeleton fb-bundle-test
$ cd fb-bundle-test
$ composer require kreait/firebase-bundle
$ cp /path/to/my/credentials.json config/service_account_credentials.json
# config/packages/firebase.yaml
kreait_firebase:
projects:
first:
default: true
credentials: '%kernel.project_dir%/config/service_account_credentials.json'
alias: 'firebase'
# src/Command/AppTestCommand.php
<?php
namespace App\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AppTestCommand extends ContainerAwareCommand
{
protected static $defaultName = 'app:test';
protected function execute(InputInterface $input, OutputInterface $output)
{
$firebase = $this->getContainer()->get('firebase');
echo json_encode($firebase->getDatabase()->getRules(), true);
}
}
bin/console app:test
then returned the database rules of my projects.
-
You are specifying that you're using "1.0" as a constraint for the bundle - I recommend using "^1.0" as a version constraint, this ensures that you are always on the stable release for that main version (the current release is 1.1.1).
composer show | grep kreait/firebase
will show you the currently installed versions of thekreait/firebase-*
packages, it should look like this -
If your results don't match, you could force newer versions by writing
"kreait/firebase-bundle": "^1.1.1"
in yourcomposer.json
-
I'm writing all this because of your notice about the dysfunctional
default
config option - this should definitely be working. -
When the Firebase PHP SDK doesn't find a credentials file at the specified location, it will try to find one by inspecting environment variables and some default locations (this is needed in Google Cloud Engine (GCE) environments. That it even tried that is an indication that it can't find or read the credentials at the location
'%kernel.root_dir%/config/model-firebase-adminsdk.json'
I am sure you already have checked the release versions and the credentials location, but could you check again? When I tried to reproduce the issue, I wall in the trap of copying the credentials with dashes -
but using underscores _
in the yaml file :D
from firebase-bundle.
well, I updated the composer json, and it looks to be working now (both, the default option and locating the json). my bad
But its not fully working yet and I would like to ask 2 more questions
- your test return a error, I think it is because I have not created a database in the firebase (and other commands as
$firebase->getAuth()->getApiClient()->downloadAccount()
return stuff), could you confirm for me?
In JSON.php line 58:
[Kreait\Firebase\Exception\InvalidArgumentException]
json_decode error: Syntax error
Exception trace:
Kreait\Firebase\Util\JSON::decode() at C:\Users\Aptor02\Documents\Projetos\Sistemas\asktospekaer\vendor\kreait\firebase-php\src\Firebase\Database\ApiClient.php:28
Kreait\Firebase\Database\ApiClient->get() at C:\Users\Aptor02\Documents\Projetos\Sistemas\asktospekaer\vendor\kreait\firebase-php\src\Firebase\Database.php:105
2. About my code, I'm trying to do
$messaging = $this->container->get('firebase')->getMessaging();
$msg = array(
'condition' => "App == 'br.com.aptor.model'",
'notification' => array(
'title' => 'titulo',
'body' => 'corpo',
)
);
$responseData = $messaging->send($msg);
but receiving error
Kreait\Firebase\Exception\Messaging\InvalidMessage:
Client error: `POST https://fcm.googleapis.com/v1/projects/aptor-model/messages:send` resulted in a `400 Bad Request` response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT" (truncated...)
at vendor\kreait\firebase-php\src\Firebase\Exception\MessagingException.php:76
at Kreait\Firebase\Exception\MessagingException->withResponse(object(Response))
(vendor\kreait\firebase-php\src\Firebase\Exception\MessagingException.php:51)
at Kreait\Firebase\Exception\MessagingException::fromRequestException(object(ClientException))
(vendor\kreait\firebase-php\src\Firebase\Messaging\ApiClient.php:54)
at Kreait\Firebase\Messaging\ApiClient->request('POST', 'messages:send', array('json' => array('message' => array('condition' => object(Condition), 'notification' => object(Notification)))))
(vendor\kreait\firebase-php\src\Firebase\Messaging\ApiClient.php:26)
Any idea about what could be the invalid argument or how to discover it?
from firebase-bundle.
Your stack trace shows that the exception is thrown in Firebase\Database\ApiClient.php
- so the exception is not triggered by $firebase->getAuth()->getApiClient()->downloadAccount()
, but probably by the $firebase->getDatabase()->getRules()
command.
I cannot confirm that the error is thrown - I tried reproducing this be deleting the database rules in the Firebase Web console, by deactivating the Database and by emptying my test database - with no success.
I will try to make the errors more descriptive in a future release. In your case, the error is that only topics are supported in the condition field (see https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json), that means you can't use App
as a condition.
You can check if you message is valid as described in https://firebase-php.readthedocs.io/en/latest/cloud-messaging.html#validating-messages with
try {
$firebase->getMessaging()->validate($msg);
} catch (InvalidMessage $e) {
print_r($e->errors());
}
In the Firebase PHP SDK, you can specify custom Guzzle Middlewares that can be used e.g. to debug HTTP Requests to the Firebase APIs - this is not yet implemented in the Bundle, but I will look to add this in one of the next releases.
from firebase-bundle.
Related Issues (20)
- Requested entity was not found. In Parser.php line 95: The JWT string must have two dots HOT 3
- Recommended usage triggers deprecation errors HOT 8
- Messaging sendAll() does not return correct feedback when there's an errorneous request HOT 3
- Compatibiliy for symfony 5 HOT 2
- kreait_firebase.my_project.messaging HOT 8
- There is no extension able to load the configuration for "kreait_firebase" HOT 3
- The definition for "kreait\firebase\factory" has no class. HOT 9
- Symfony secrets management support HOT 2
- [feature request] Trigger Event(s) HOT 2
- CloudMessage in service ? HOT 4
- Ability to use guzzle middleware? HOT 2
- PHP 8 Support HOT 2
- Failed to load class Google\Cloud\Firestore\FirestoreClient used by typed property Kreait\Firebase\Firestore::$client during preloading HOT 5
- Symfony 6 compatibility HOT 1
- 2.6.0 calls setDeprecated with incorrect parameters for Symfony 4.4 HOT 2
- Feature request: support for FCM localization HOT 1
- Cannot autowire "Kreait\Firebase\Contract\Auth" HOT 2
- Symfony 6.1 Support HOT 1
- Cannot autowire service "App\Service\PushService": argument "$messaging" of method "__construct()" references interface "Kreait\Firebase\Contract\Messaging" but no such service exists HOT 11
- [Possible Bug] sendMulticast isn't working anymore. HOT 4
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 firebase-bundle.