Problems when adding a group of devices with firebase CURL

0

Good afternoon to the whole community, I am using the push notification service of firebase with CURL and laravel however when I want to add a group of devices I get the following error

$server_key = 'server_key';

    $url = "https://android.googleapis.com/gcm/googlenotification";

    $senderId = "111111111";
    $name = "Prueba";
    $registrationID = array('obtengo el registro id del que quiero agregar');
    $notificationkey = 'obtengo la notificationKey';

    $headers = array(
        'Content-Type: application/json',
        'Authorization: key='.$server_key,
        'project_id:'. $senderId
    );


    $addkey = array(
        'operation' => 'add',
        'notification_key_name' => $name,
        'registration_ids' => $registrationID,
        'notification_key' => json_encode($notificationkey),
    );
    $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_POSTFIELDS, json_encode($addkey));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);        

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;

Is my next question in which part of my code is wrong? I modified it several times and I always got the same answer ERROR 401 I hope you can guide me. Thanks

    
asked by jara 07.05.2018 в 22:01
source

1 answer

0

You are occupying the GCM service and not the FCM service.

This example helped me a lot: link

    
answered by 09.05.2018 в 00:50