【发布时间】:2018-06-09 22:44:13
【问题描述】:
我现在必须学习通过火力基地编写移动应用程序网络服务。 我点击了这个链接:https://firebase-php.readthedocs.io/en/stable/
在我的核心网站中,我创建了 web 服务文件夹,然后创建了我的 fire.php 文件。这个文件代码在这里,
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyC_vb5G9qs3NJsywbR34el1RaPj2HDhwNg';
$firebase = (new Factory)
->withServiceAccountAndApiKey($serviceAccount, $apiKey)
->withDatabaseUri('https://workarea-cb10b.firebaseio.com')
->create();
$database = $firebase->getDatabase();
$newPost = $database
->getReference('blog/posts')
->push([
'title' => 'Post title',
'body' => 'This should probably be longer.'
]);
$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-
$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();
我必须在这里调用我的支持文件:https://github.com/kreait/firebase-php/
但我还是得到了一个:
致命错误:未捕获的错误:“Kreait\Firebase\ServiceAccount”类 没有找到 /opt/lampp/htdocs/workarea/webservice/firebase/fire.php:13 堆栈 跟踪:#0 {main} 投入 /opt/lampp/htdocs/workarea/webservice/firebase/fire.php 在第 13 行
issue 必须解决这个问题。请检查并帮助我。
我的composer.json 文件
{
"name": "kreait/firebase-php",
"description": "Firebase Admin SDK",
"keywords": ["firebase", "google", "sdk", "api", "database"],
"homepage": "https://github.com/kreait/firebase-php",
"license": "MIT",
"authors": [
{ "name": "Jérôme Gamez", "homepage": "https://github.com/jeromegamez" }
],
"require": {
"php": "^7.0",
"ext-mbstring": "*",
"ext-openssl": "*",
"fig/http-message-util": "^1.1",
"google/auth": "^0.11.0|^1.0",
"guzzlehttp/guzzle": "^6.2.1",
"kreait/firebase-tokens": "^1.1.1",
"lcobucci/jwt": "^3.2",
"mtdowling/jmespath.php": "^2.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"phpstan/phpstan-phpunit": "^0.9.2",
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": {
"Kreait\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Kreait\\Tests\\": "tests"
}
},
"config": {
"platform": {
"php": "7.0"
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
}
}
【问题讨论】:
-
我们可以看看你的 composer.json 文件吗?
-
这是我的作曲家文件
-
不,这是你的 fire.php 文件
-
sry 我无法正确发送我的作曲家文件。我将通过评论发送文件
-
编辑您的问题。请不要使用这样的 cmets。