title: GCM sending with curl (php)
body: <p>I'm trying to send a message to an Android phone but keep getting response code 401 with text: Unauthorized. Also I keep reading different stories on what key to use, I know of 3 keys: the project ID (number), the Key for server apps and the Key for browser apps. So I have tryed them all 3, all with the same result.</p>
  
  <p>My code:</p>
  
  <pre><code>$headers = array("Content-Type" =&gt; "application/json", "Authorization" =&gt; "key=" . "mykey");
      $data = array(
          'data' =&gt; $messageText,
          'registration_ids' =&gt; array($deviceRegistrationId)
      );
  
      $ch = curl_init();
  
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
      curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
      curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
      error_log(json_encode($data));
      $response = curl_exec($ch);
      curl_close($ch);
      error_log($response);
  </code></pre>