2

I tried with web api key which i got from > firebase console> My Project> project setting>General Tab. NOTE : Currently I am not using paid developer account. I just create a new google account and created a project.

$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;
masud_moni
  • 1,121
  • 16
  • 33

2 Answers2

0

Click on Setting Icon on Right of Overview navigation option and select Project Setting from popup and select cloud Messaging tab you will see the Server Key and Legacy Server Key.

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
0

As of 2023

Go to the firebase console. Select your project. Goto Project settings->Service accounts then scroll down to "Generate new private key". A json file will be downloaded with the details you need.

Robby Lebotha
  • 1,211
  • 11
  • 9