0

i'm trying to get data from a firebase db, but as it's my first time using it i'm kind of stuck. This is the code i'm using:

$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); 

but the response i'm getting is "error" : "Unauthorized request." . I see in the docs that I have to add scope https://www.googleapis.com/auth/userinfo.email but I have no idea how as I've tried several ways with no avail. Any help would be greatly appreciated.

I've tried also using the legacy server key and "auth=$token" but it did not work as well, but getting "Could not parse auth token" even with urlencode()

STL
  • 65
  • 2
  • 8

2 Answers2

0

Found the problem. Was not using the right SERVER KEY/Secret. You can see where to find the correct one here: Firebase - Where is My Account Secret in the New Console?

STL
  • 65
  • 2
  • 8
0

Kreait has an awesome library to let you use Firebase in PHP https://github.com/kreait/firebase-php

https://firebase-php.readthedocs.io/en/latest/ https://github.com/SamarRizvi/firebase-php-example