In PB scheint alles ok, außer ein Eintrag. Aber ich finde den Fehler nicht!
Bekomme von firebase immer die Meldung!
"registration_ids" field is Not a JSON Array"
(Der Fehler erscheint natürlich nur mit den richtigen Key, Token und Link)
Wäre super nett wenn mir da jemand helfen könnte! Danke!
Beide Codes lassen sich direkt ausführen mit "httpbin.org"
Den einzigen unterschied den ich feststellen konnte war der.
; PHP OK = "registration_ids": [ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ]
; PB ERROR = "registration_ids": "[\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"]"
Aber wie behebe ich den ? Irgendwas gehe ich da immer falsch an.
PHP:
Code: Alles auswählen
<?php
$key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
$token = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
$path_to_firebase_cm = "https://httpbin.org/post";
# $path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$token=array($token);
$fields = array(
'registration_ids' => $token,
'priority' => 10,
'notification' => array('title' => $type_of_notification, 'body' => $title ,'sound'=>'Default'),
);
$headers = array(
'Authorization:key=' .$key ,
'Content-Type:application/json'
);
$ch = curl_init($path_to_firebase_cm);
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
print "<body text='blue'>";
$show = str_replace(",", ",<br>", $result);
print $show;
print ("<br>"."<br>"."<br>");
return $result;
?>
Code: Alles auswählen
InitNetwork()
#JSON_DATA = 1
#JSON_TOKEN = 2
key$ = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
token$ = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
path_to_firebase_cm$ = "https://httpbin.org/post";
; path_to_firebase_cm$ = "https://fcm.googleapis.com/fcm/send"
If CreateJSON(#JSON_DATA)
Person = SetJSONObject(JSONValue(#JSON_DATA))
If CreateJSON(#JSON_TOKEN)
ArrayValue = SetJSONArray(JSONValue(#JSON_TOKEN))
NumValue = AddJSONElement(ArrayValue)
SetJSONString(NumValue, token$)
SetJSONString(AddJSONMember(Person, "registration_ids"), ComposeJSON(#JSON_TOKEN))
SetJSONInteger(AddJSONMember(Person, "priority" ), 10)
Values = SetJSONObject(AddJSONMember(Person, "notification"))
SetJSONString(AddJSONMember(Values, "body" ), "")
SetJSONString(AddJSONMember(Values, "sound" ), "Default")
SetJSONString(AddJSONMember(Values, "title" ), "")
NewMap Header$()
Header$("ContentType") = "text/plain"
Header$("Authorization") = "key=" + key$
Header$("Content-Type") = "application/json"
HttpRequest = HTTPRequest(#PB_HTTP_Post, path_to_firebase_cm$, ComposeJSON(#JSON_DATA), 0, Header$())
If HttpRequest
Debug HTTPInfo(HTTPRequest, #PB_HTTP_Response)
FinishHTTP(HTTPRequest)
EndIf
EndIf
EndIf
End