Wenn ich versuche, eine gcm Nachricht über die unten php zu schicken, ich diesen Fehler:Google Cloud Messaging gibt ungültige Registrierung
{ "multicast_id": 8958574426215974401 "Erfolg": 0, "Fehler": 1 , "canonical_ids": 0, "results": [{"error": "InvalidRegistration"}]}
Der Server-API-Schlüssel ist jedoch genau das, was Google mir gegeben hat, und das gcm_token wird genau gespeichert meine Datenbank. Ich weiß nicht, wo das Problem liegt.
Hier ist meine Server-Seite PHP:
<?php
require 'db_connect.php';
// API access key from Google API's Console
define('API_ACCESS_KEY', 'AIzaSyREST OF MY KEY');
//insert the message into a database
$sql = "SELECT gcm_token FROM users WHERE user_id='1' LIMIT 1;";
// preform
if (!mysqli_query($Thesisdb, $sql)) {
printf("Errormessage: ", mysqli_error($Thesisdb));
mysqli_close($Thesisdb);
} else{
$results = mysqli_query($Thesisdb, $sql);
$registrationIds = array($results);
// prep the bundle
$msg = array
(
'message' => '$user',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
?>
den Sinn macht, wie ich Boolesche Werte bekommen, als ich var_dump(), um die mysqli_query. Vielen Dank! –
Erwähnung nicht @ MichaelGulik –