2

私はfirebase console> My Project>プロジェクト設定> Generalタブから得たWeb APIキーを試しました。 注:現在、私は有料の開発者アカウントを使用していません。私はちょうど新しいGoogleアカウントを作成し、プロジェクトを作成しました。 Overviewナビゲーションオプションの右にあるアイコンをSettingPHPのcurlリクエストの認証ヘッダーで解析されるFCMサーバーキーを取得する方法は?

$url = 'https://fcm.googleapis.com/fcm/send'; 
$server_key = '??????WHAT TO PUT HERE ????'; 
$fields = []; 
$data = []; 
$data['type'] = $type; 
$data['title'] = $title; 
$data['message'] = $message; 
$data['sound'] = 'default'; 
$fields['data'] = $data; 
if (is_array($id)) { 
    $fields['registration_ids'] = $id; // array of registration ids 
} else { 
    $fields['to'] = $id; single registration id 
} 
//$fields['content_available'] = "true"; 
//header with content_type api key 
$headers = array(
    'Content-Type:application/json', 
    'Authorization:key=' . $server_key 
); 
$notification = array(); 
$notification['title'] = $title; 
$notification['body'] = $message; 
$notification['sound'] = 'default'; 
$notification['click_action'] = $type; 
$fields['notification'] = $notification; 

$fields = json_encode($fields); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
$result = curl_exec($ch); 
curl_close($ch); 
return $result; 

答えて

0

クリックし、ポップアップからProject Settingを選択し、cloud Messaging]タブを選択しますServer KeyLegacy Server Keyが表示されます。

+0

ありがとうございます! –

関連する問題