Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase: "Could not parse auth token."

Hello i am using firebase with php and using this library.

I am getting this error."Could not parse auth token."

My auth token is correct because i have used same token with node.js also.

my code looks like this

       require "vendor/autoload.php";
       const DEFAULT_URL = 'https://xxxxxxxxx.firebaseio.com';
       const DEFAULT_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

       $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN );  

        $data = [
        "Website_Name"=> $Website_Name,
        "Username" =>  $Username,
       "Password"=> $Password,
       "website_link"=> $website_link,
       "id"=> $id,
       ];



        $path = "per_users";
        $res = $firebase->push('/per_users', $data);
        // per_users is the name of the table
        var_dump($res); 

can you please tell me what exactly i am doing wrong. thanks.

like image 896
Manpreet Oberoi Avatar asked Sep 17 '16 19:09

Manpreet Oberoi


2 Answers

I found the following solution worked, if anyone would still want to use topic starter's library:

  1. Go to Firebase Console and select your project.
  2. Go to Project Settings (press the gear icon beside Overview in the upper left)
  3. Go to the Service Accounts tab
  4. Select Database Secrets, show and copy the database secret key for the library's const DEFAULT_TOKEN

enter image description here

like image 133
raiser00 Avatar answered Sep 19 '22 23:09

raiser00


I'm using somethink like this and it works for me. without any library. simple.

// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR_FIREBASE_API_KEY' ); //<--- here comes your api key from firebase
$registrationIds = array( "devices firebasetoken here." ); //<--- here comes device token (firebase generated token.)
// prep the bundle
$msg = array(
    'body'  => "message text",
    'title'     => "message title",
    'vibrate'   => 1,
    'sound'     => 1,
);
$fields = array(
        'registration_ids'  => $registrationIds,
        'notification'      => $msg
    );

$headers = array(
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json'
    );

 $ch = curl_init();
 curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
 curl_setopt( $ch,CURLOPT_POST, true );
 curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
 curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
 curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
 curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
 $result = curl_exec($ch );
 curl_close( $ch );
 echo $result;
like image 41
MRustamzade Avatar answered Sep 22 '22 23:09

MRustamzade