Git Product home page Git Product logo

Comments (15)

jeromegamez avatar jeromegamez commented on July 22, 2024 3

In Laravel, you could do for example:

$database = app('firebase.firestore')->database();

$var_list = $database->collection('tokens')->document('tokens')->snapshot();

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 22, 2024 1

If youβ€˜re satisfied with the outcome, of course :). Please fell free to create a new issue or ask on Discord if you have further questions!

from laravel-firebase.

chiendv avatar chiendv commented on July 22, 2024 1

Today I suddenly got this issue after run config:cache then I figured out that it only read FIREBASE CREDENTIALS in .env not GOOGLE_APPLICATION_CREDENTIALS

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 22, 2024

Hm, this looks like if perhaps the composer autoloader has lost some information - could you try doing a composer dumpautoload and see if that fixes something? And ensure that your credentials file is really unchanged?

I'm just guessing, but the error hints at the project ID not being available, and the project ID is always included in the service account JSON.

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

Thank you for your prompt reply.
Since an exception was found in Discover.php, I started running after clearing the cache.

Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "FIREBASE_CREDENTIALS" is not set.
Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "GOOGLE_APPLICATION_CREDENTIALS" is not set.
Kreait\Firebase\ServiceAccount\Discovery\FromGoogleWellKnownFile: The well known file is not readable or invalid
cURL error 6: Could not resolve host: metadata.google.internal (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

We are now thinking about how to respond.
Is there a way to load firebase_credential.json without using Discover.php when doing new Factory () ?

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

I tried $factory = (new Factory())->withServiceAccount('/var/www/server/firebase.json');;

And FIREBASE_CREDENTIALS key is not set.
The process is end, nothing error.
Is this the way it is?

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 22, 2024

That's the way it is, yes. As soon as you provide a service account, the factory will not try to auto-discover the credentials after that.

You are not receiving the error in that line, the most common reason for this error is that you are not using the same factory that you initialized. As an example:

$factory = (new Factory())->withServiceAccount('...');

Here, the second line will return a new instance of the factory, the previous `$factory` will be untouched
$factory->withDatabaseUrl('...');

// Correct would have been
$factory = $factory->withDatabaseUrl('...');

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

Hi, Kreait Team.

Thank you.
With your advice, my project was able to move on.
Thanks for the quick reply and courteous response.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 22, 2024

Oh, I just realized that we are in the context of the Laravel Package πŸ˜… - here you normally shouldn't need to invoke the Factory manually at all.

Could you tell me more about why you are doing new Factory() instead of using app('firebase.<component>') or dependency injection?

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

I saw this page and wrote the program.

https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html

Now, when I reviewed Readme.md again, it was written. I missed it without noticing.
I will try again!

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

Hi, jeromegamez.

The program I wrote now looks like.

use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Kreait\Firebase\Messaging\WebPushConfig;
            // This code is get Cloud Firestore collections.
            $factory = (new Factory())->withServiceAccount(config('firebase.config'));
            $firestore = $factory->createFirestore();
            $database = $firestore->database();
            $var_list = $database->collection('tokens')->document('tokens')->snapshot();

How can I write this in a form suitable for Laravel without using "new factory ()"?
I am glad that it is also an example to be helpful.

from laravel-firebase.

ShinoharaTa avatar ShinoharaTa commented on July 22, 2024

Thank you for your reply.
I tried as you say and it was successful.
Thanks for the quick response.

It was not a problem with your library.
Can I close this issue?

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 22, 2024

The behaviour should be that it first tries to read from FIREBASE_CREDENTIALS and from GOOGLE_APPLICATION_CREDENTIALS if the former is not set. If both are set, FIREBASE_CREDENTIALS take precedence, even if it's set with an empty value. (

'file' => env('FIREBASE_CREDENTIALS', env('GOOGLE_APPLICATION_CREDENTIALS')),
)

from laravel-firebase.

JHIH-LEI avatar JHIH-LEI commented on July 22, 2024

today I have same problem after I ran php artisan config:cache.

After I ran: php artisan config:clear
Problem solve.

from laravel-firebase.

SamMakesCode avatar SamMakesCode commented on July 22, 2024

For anyone who comes after me, I had this issue when using google/cloud-firestore directly. I created a FirestoreServiceProvider which registered a singleton, but I failed to register the service provider in config/app.php

from laravel-firebase.

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.