2016-09-17 100 views
1

你好,我使用的是firebase和php,并使用这个libraryfirebase:“无法解析身份验证令牌。”

我得到这个错误。“无法解析auth令牌。”

我的身份验证令牌是正确的,因为我也使用了与node.js相同的令牌。

我的代码看起来像这样

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

可以请你告诉我,究竟我做错了。 谢谢。

回答

0

我正在使用一些像这样的想法,它适用于我。没有任何图书馆。简单。

// 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; 
+0

你能指导我一点点..我应该如何在我的代码中使用它?因为它看起来完全不同,像卷曲和所有的东西 –

+0

我已经改变了代码并添加了你应该改变的地方和内容。这是非常简单的代码。 – MRustamzade

+0

我为自己使用的这段代码,它工作的很完美。 (我现在chenged):) – MRustamzade

0

我发现下面的解决方案工作,如果有人还是会想使用主题起动器library

  1. 转到Firebase Console,并选择您的项目。
  2. 转到项目设置(按下左上角概述旁边的齿轮图标)
  3. 转到服务帐户选项卡
  4. 选择数据库的秘密,展示和复制数据库的密钥对图书馆的const DEFAULT_TOKEN

enter image description here