firebase: “Could not parse auth token.”

筅森魡賤 提交于 2019-12-04 13:46:01

问题


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.


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/39550635/firebase-could-not-parse-auth-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!