我正在尝试使用 REST 使用 php 写入 firebase,但我一直被拒绝权限
我正在使用这样的测试文件:
$url = 'https://my.firebase.url/';
$atoken = '?auth=MY FIREBASE SECRET';
$fb = new fireBase($url);
$todos = array(
'name' => 'Pick the milk',
'priority' => 1
);
$todoPath = '/test/test';
printf("Database: %s\n", $url);
printf("Sending data to %s\n", $todoPath);
$response = $fb->set($todoPath, $todos.$atoken);
printf("Result: %s\n", $response);
printf("Reading data from %s\n", $todoPath);
$response = $fb->get($todoPath);
printf("Result: %s\n", $response);
我设置了规则,只有特定的授权用户“我”管理员可以写入火力库,但任何人都可以从中读取。当代码在 Javascript 中时这很好,因为我会登录并获得授权。但现在它在 php 中,我认为“秘密”可以完成这项工作,或者至少我被 firebase DOCS 引导相信这一点。
那么我做错了什么?
谢谢!
更新:
所以我改变了:
$atoken = '?auth=MY FIREBASE SECRET';
成为
$atoken = '.json?auth=MY FIREBASE SECRET';
我把它放在这里:
printf("Sending data to %s\n", $todoPath.$atoken);
$response = $fb->set($todoPath.$atoken, $todos);
printf("Result: %s\n", $response);
printf("Reading data from %s\n", $todoPath.$atoken);
$response = $fb->get($todoPath.$atoken);
printf("Result: %s\n", $response);
现在我得到这个错误:
04Database: https://MYDATABASE/ Sending data to /test/test.json?auth=MY FIREBASE SECRET Result: { "error" : "invalid_token: Could not parse auth token." } Reading data from /test/test.json?auth=MY FIREBASE SECRET Result: { "error" : "invalid_token: Could not parse auth token." }