Giter Club home page Giter Club logo

Comments (3)

jeromegamez avatar jeromegamez commented on May 18, 2024

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 composer_show

  • 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

from firebase-bundle.

Eldhelion avatar Eldhelion commented on May 18, 2024

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

  1. 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.

jeromegamez avatar jeromegamez commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.