Reputation: 11
When I'm using gcm push notification,
Field"data"mustbeaJSONarray: {
"details": [
{
"regid": "APA91bH8zxTxfoSLWhE21IbTR9a10cvIcm17-zsPY_0OAy3JhO_8gTwMwwAUd_4vZiLu5UF4A1m8R3TEIffDaChVR0y2us9iebngkaWlOM34ix4PUeOgIoM9aGOcxLLECAGjKNSwupTY0p2O0BeXjSCp8RYFaD-xzg",
"status": "true",
"post_userid": "34",
"post_id": "7",
"postuser_name": "dev",
"message": "gggggg"
}]}
and that give me error: "Field data must be a JSON array"
please guide me
My code :
$fields = array('data'=> $message);
$headers = array('Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json' );
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '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;
Upvotes: 1
Views: 1135
Reputation: 394146
Well, your JSON doesn't look like it's supposed to look. It should be something like that :
{
"data": {
"status": "true",
"post_userid": "34",
"post_id": "7",
"postuser_name": "dev",
"message": "gggggg"
},
"registration_ids":["APA91bH8zxTxfoSLWhE21IbTR9a10cvIcm17-zsPY_0OAy3JhO_8gTwMwwAUd_4vZiLu5UF4A1m8R3TEIffDaChVR0y2us9iebngkaWlOM34ix4PUeOgIoM9aGOcxLLECAGjKNSwupTY0p2O0BeXjSCp8RYFaD-xzg"]
}
Upvotes: 1