0

i am using gcm service from 5 6 months before and its was working fine on server and applicaion side. but suddenly its got unauthorized error while i was integrating with another application, but device successfully registered with gcm and php got unauthorized error 401. i use one gcm api key in more then one application. It is working fine on local server using wamp

Below is my php code

public function send_notification($registatoin_ids, $message) {
                  $url ='https://android.googleapis.com/gcm/send';
    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }

    // Close connection
    curl_close($ch);
    echo $result;
}
  • Possible duplicate of [Android API key for GCM is suddenly invalid? Unauthorized (401) error](http://stackoverflow.com/questions/37789264/android-api-key-for-gcm-is-suddenly-invalid-unauthorized-401-error) – AL. Jun 16 '16 at 01:16
  • Look at my answer in the link above, a lot of people have been experiencing the same thing. Cheers! – AL. Jun 16 '16 at 01:17
  • Possible duplicate of http://stackoverflow.com/questions/12619759/google-gcm-server-returns-unauthorized-error-401 – Android Enthusiast Jun 16 '16 at 06:55

0 Answers0