firebase:“无法解析身份验证令牌". [英] firebase: "Could not parse auth token."

查看:101
本文介绍了firebase:“无法解析身份验证令牌".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在将Firebase与php一起使用,并使用此.

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

我收到此错误.无法解析身份验证令牌."

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

我的身份验证令牌是正确的,因为我也已将相同的令牌与node.js一起使用.

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

我的代码看起来像这样

       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.

推荐答案

我正在使用这种方法,它对我有用.没有任何图书馆.简单.

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;

这篇关于firebase:“无法解析身份验证令牌".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆