2016-09-17 101 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