Closed Eldhelion closed 6 years ago
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 the kreait/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 your composer.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
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
$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?
1.
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.
2.
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.
1. Which version of
kreait/firebase-php
andkreait/firebase-bundle
are you using?"kreait/firebase-bundle": "1.0" kreait/firebase-php ^4.0
2. Which version of PHP are you using?
7.1.9
3. What's the issue? and 4. Code that lead to the issue
I setup the bundle as show in the readme my config.yml is
The php I created more or less as done in the
app:fcm:send-message
example ( https://github.com/jeromegamez/firebase-php-examples )But despite having indicated the path to the json in the config.yml, I'm receiving this error
also, the doc, say that I could set default: true, but decommenting this line result in