0
public function fcm_command($token,$command){
    $path_to_fcm = 'https://fcm.googleapis.com/v1/projects/projects/messages:send';
    
    //Taglock Server Key
    $server_key = "";
    $headers = array(
        'Authorization:key=' .$server_key,
        'Content-Type:application/json'
        );
    $fields = array('to'=>$token,'data'=>array('command'=>$command));
    $payload = json_encode($fields);
    $curl_session = curl_init();
    curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
    curl_setopt($curl_session, CURLOPT_POST, true);
    curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
    $res = curl_exec($curl_session);
    curl_close($curl_session);
    return array('status'=>REST_Controller::HTTP_OK,'message'=> 'Command sent to device');
}

I am using old $server_key and only updated $path_to_fcm = 'https://fcm.googleapis.com/v1/projects/projects/messages:send';, but notification not getting. Do I need to generate new server key or old is required?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jitu
  • 1
  • 1

1 Answers1

0

Authentication/authorization for the v1 API no longer works with a server key. I recommend that you read the documentation on authorizing send requests to find your current options, and also have a look at:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807