PHP 与 Firebase 的连接如何工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28293038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:47:32  来源:igfitidea点击:

How does PHP connection to firebase work?

phpfirebase

提问by Lyka San Pedro Hementera

If you have the time to read the firebase-phpdocumentation, you can see there how to use the helper library to "connect" to firebase. But unfortunately, I think that the connection could only be established by phpunit, in other words, output can only be seen in the terminal. Since when you run the php pages in your browser, it will return fatal errors. Does anyone know how to use the helper libraryto connect to the firebasedata without using phpunit? Thank you in advance.

如果您有时间阅读firebase-php文档,您可以在那里看到如何使用帮助程序库“连接”到firebase。但不幸的是,我认为连接只能通过phpunit建立,也就是说,输出只能在终端中看到。因为当您在浏览器中运行 php 页面时,它会返回致命错误。没有人知道如何使用助手库连接到火力点的数据,而无需使用PHPUnit的?先感谢您。

回答by Jens A. Koch

Using the lib is very easy, when you just look at the source code of the tests.

使用 lib 非常简单,只需查看测试的源代码即可。

There are two kinds of tests:

有两种测试:

Now, in order to use firebase-php, you would simply do the same things as in the real functionality test. Include the lib, prepare the connection object with login credentials and then call the method you want. The interfacedescribes, which methods you can expect in the firebaseLib class - or just look at the lib source itself.

现在,为了使用 firebase-php,您只需执行与实际功能测试相同的操作。包括 lib,准备带有登录凭据的连接对象,然后调用所需的方法。该接口描述了您可以在 firebaseLib 类中使用哪些方法 - 或者只是查看lib 源代码本身

This piece of code should get you started:

这段代码应该让你开始:

require '/path/to/libs/firebase-php/firebaseLib.php';
$url = '...';
$token = '...';
$firebase = new Firebase($url, $token);
$firebase->get('something/from/somewhere');


If you fetch the library via composer, you might declare an autoloading classmap, too. The author hasn't done this, yet.

如果您通过 获取库composer,您也可以声明一个自动加载类映射。作者还没有做到这一点。

{
    "autoload": {
        "classmap": ["vendor/ktamas77/firebase-php/firebaseLib.php"]
    }
}

Then simply require Composer's Autoloader with require "vendor/autoload.php";and new Firebaseto autoload the class.

然后只需要 Composer 的 Autoloader withrequire "vendor/autoload.php";new Firebase来自动加载类。



How to get the auth token

如何获取授权令牌

  • open your firebase console
  • go to project settings
  • go to the database
  • then copy the secret key
  • 打开您的 Firebase 控制台
  • 转到项目设置
  • 去数据库
  • 然后复制秘钥

get-firebase-token

获取-firebase-token