"registration_ids" - Feld nicht ein JSON-array (FB)
Ich bin vor problem mit der FB "registration_ids". Wenn ich senden Sie die Anfrage aus Rest-Client bekomme ich die erfolgreiche Antwort.
{"multicast_id":4650719213012935695,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1468837777484579%214918aff9fd7ecd"},{"message_id":"0:1468837777484484%214918aff9fd7ecd"}]}
Aber wenn ich Anrufe, gleiche php-Skript von meinem Android-Anwendung gibt mir Fehler in der Antwort. (Ich bekam die Antwort in Charles Proxy)
"registration_ids" field is not a JSON array
Hier ist mein php-Skript
function fetchFirebaseTokenUsers($message) {
$query = "SELECT token FROM firebase_tokens";
$fcmRegIds = array();
if($query_run = mysqli_query($this->con, $query)) {
while($query_row = mysqli_fetch_assoc($query_run)) {
array_push($fcmRegIds, $query_row['token']);
}
}
if(isset($fcmRegIds)) {
$pushStatus = $this->sendPushNotification($fcmRegIds, $message);
}
}
function sendPushNotification($registration_ids, $message) {
ignore_user_abort();
ob_start();
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $registration_ids,
'data' => $message,
);
define('GOOGLE_API_KEY', 'AIzaSyC.......VdYCoD8A');
$headers = array(
'Authorization:key='.GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if($result === false)
die('Curl failed ' . curl_error());
curl_close($ch);
return $result;
ob_flush();
}
- Könnten Sie Ihr Android-code?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich verwendet
to
anstatt array des FB-Token alsregistration_ids
. Ursacheregistration_ids
haben das limit von 1000, die Zahl der FB-Token nur https://firebase.google.com/docs/cloud-messaging/http-server-ref.to
Werke für die einzelnen Tokens, richtig?Wenn Sie
registration_ids
Sie müssen die übergebenen Daten werden in der Reihe wie folgt:PHP:
Wenn registration_ids ist nur ein Token, wie es auf
https://firebase.google.com/docs/cloud-messaging/http-server-ref
sollten Sie das Feld 'an'.
FCM erfordert registered_ids ein JSON-Array mit Indizes, beginnend bei 0.
Ich habe den gleichen Fehler, da die Indizes, in denen nicht diese. Ich löste es mit Hilfe der PHP Funktion " array_values.
Ich hatte das ähnliche Szenario, wo ich erstellen Sie eine GCM-Gruppe für die Registrierung des Nutzers Token & Fehler ist aufgetreten. Ich fand es später heraus, dass ich war nicht nach corrent JSON-format erwähnt auf fire-Basis
Lösung:
Erstellen Sie ein Modell
dann serialisieren
machen und einen post-Aufruf von google.