Error messages returned from GCM are misleading. Most likely, you have a 
problem with your key, the JSON you're sending or a combination of other 
issues. Double check what you're sending. Most likely it's a simple error.

There's also an issue with unquoted numeric values. Send all data 
parameters as quoted strings.

-John Coryat


On Wednesday, September 5, 2012 10:49:30 AM UTC-5, saex wrote:
>
> Searching for some info about how to send notifications using GCM but with 
> PHP instead of servlets, i found this: 
> http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging
>
> I tested the working code of the responses of these questions, also i 
> created a Key for browser apps (with referers), and i give permissions to 
> this ip: *.mywebsite.com/* (te php file is on this url: "
> http://www.mywebsite.com/~jma/cHtml5/cap/kk.php";)
>
> But i'm getting this response: **Unauthorized Error 401**
>
> What i'm doing wrong?
>
> this is the php file: 
>
>     <?php
>         // Replace with real server API key from Google APIs          
>         $apiKey = "fictional key";
>         
>         // Replace with real client registration IDs
>         $registrationIDs = array( 
> "APA91asdasdSDGGS232S13S4213abGqiNhCIXKjlxrkUYe_xTgTacNGB5n16b380XDd8i_9HpKGRHkvm8DDet4_WK3zumjDEKkTRWLgPS7kO-BrKzWz7eWFQaDD9PJ8zA6hlSqL9_zH21P8K22ktGKmo_VIF6YAdU9ejJovrKBTpgQktYkBZBf9Zw","APAasdasd32423dADFG91bHYYxYB7bFiX5ltbJt6A-4MBiNg7l4RS4Bqf3jIfYviaaUfZ810XJo2o66DY9-jdeJk_JR8FIZCyrmCv-eu_WLkGZ8KaoHgEDR_16H2QPm98uHpe1MjKVXbzYc4J89WMmcIrl5tHhWQnIQNzaI6Zp6yyFUNUQ");
>         
>         // Message to be sent
>         $message = "Test Notificación PHP";
>         
>         // Set POST variables
>         $url = 'https://android.googleapis.com/gcm/send';
>         
>         $fields = array(
>             'registration_ids' => $registrationIDs,
>             'data' => array( "message" => $message ),
>         );
>         
>         $headers = array(
>             'Authorization: key=' . $apiKey,
>             '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 );
>         //curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
>         
>         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
>         //curl_setopt($ch, CURLOPT_POST, true);
>         //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
>         
>         // Execute post
>         $result = curl_exec($ch);
>         
>         // Close connection
>         curl_close($ch);
>         echo $result;
>         //print_r($result);
>         //var_dump($result);
>     ?>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to