我正在尝试从Firebase数据库中获取数据,但是由于这是我第一次使用它,因此有点卡住了。这是我正在使用的代码:
$url = 'https://PROJECT_ID.firebaseio.com/runs/upcoming.json';
$token ='SERVER_KEY_TOKEN';
$headers = array(
'Content-Type:application/json',
'Authorization: Bearer '.$token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "?access_token=" . $token);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
但是我得到的响应是“错误”:“未授权的请求”。。我在文档中看到必须添加范围https://www.googleapis.com/auth/userinfo.email,但是我不知道如何尝试几种无效的方法。任何帮助将不胜感激。
我也尝试过使用旧版服务器密钥和“ auth = $ token”,但效果不佳,但是即使使用urlencode()也获得“无法解析身份验证令牌”
答案 0 :(得分:0)
发现了问题。没有使用正确的SERVER KEY / Secret。您可以在此处查看在哪里找到正确的地址:Firebase - Where is My Account Secret in the New Console?
答案 1 :(得分:0)
Kreait有一个很棒的库,可让您在PHP中使用Firebase https://github.com/kreait/firebase-php
https://firebase-php.readthedocs.io/en/latest/ https://github.com/SamarRizvi/firebase-php-example