title: Getting Unauthorized Error 401 in Firebase Cloud Messaging in cURL command
body: <p>I'm going to send Firebase Cloud Messaging and the problem that I'm facing is I get an Unauthorized Error 401.</p>
  
  <p>I got the security key from my Firebase website then set it. The device token is already in database and I read from database with no problem.
  This is my code so far:</p>
  
  <pre><code>&lt;?php
  
  function send_notification($tokens, $message)
  {
      $url = 'https://fcm.googleapis.com/fcm/send';
      $fields = array('registration_ids' =&gt; $tokens, 'data' =&gt; $message);
      $headers = array('Authorization: key=' . "My Firebase key", 'Content-Type: application/json');
      echo "work well before init curl";
      $ch = curl_init();
      echo "init well";
      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);
      echo "init finishe well";
      $result = curl_exec($ch);
      echo "Execute to get result";
      if ($result === false) {
          die('Curl failed: ' . curl_error($ch));
      }
      curl_close($ch);
      echo "function finished well";
      return $result;
  }
  
  $conn = mysqli_connect("localhost", "root", "mysql_password", "FCM") or die("Error connecting");
  
  $sql = " Select Token From users";
  $result = mysqli_query($conn, $sql);
  $tokens = array();
  if (mysqli_num_rows($result) &gt; 0) {
      while ($row = mysqli_fetch_assoc($result)) {
          $tokens[] = $row["Token"];
      }
  }
  mysqli_close($conn);
  $message = array("message" =&gt; " FCM PUSH NOTIFICATION TEST MESSAGE");
  $message_status = send_notification($tokens, $message);
  echo $message_status;
  ?&gt;
  </code></pre>