Send notification with Firebase API

Discussion in 'General Discussion' started by aksoyhlc, Oct 7, 2019.

  1. aksoyhlc

    aksoyhlc New Member

    Joined:
    Sep 17, 2017
    Messages:
    3
    Likes Received:
    0
    Hello there. I would like to send notification using Firebase API. My APIs are ready, but I can't send notifications with the API because I don't know the topic part of 'to' => "/topics/xxxxx" in this field. The notification appears to have been sent, but users are not notified. What did you write to the topic section when writing the application?

    My code:

    PHP:
    define('API_ACCESS_KEY','xxxxxxxxxxxxxxxxxxxxxxx');
    $fcmUrl 'https://fcm.googleapis.com/fcm/send';
    $notification = [
    'title' =>'xxxxxxxxxxxxxxxx',
    'body' => 'yyyyyyyyyyyyyyy.'
    ];
    $extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
    $fcmNotification = [
    "content-available"=>"1",
    'to' => "/topics/All"//single token
    'notification' => $notification,
    'data' => $extraNotificationData
    ];
    $headers = [
    'Authorization: key=' API_ACCESS_KEY,
    'Content-Type: application/json'
    ];
    $ch curl_init();
    curl_setopt($chCURLOPT_URL,$fcmUrl);
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_HTTPHEADER$headers);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode($fcmNotification));
    $result curl_exec($ch);
    curl_close($ch);
    echo 
    $result;
    returned date:

    Code:
    {"message_id":4709853598141.......}
     
    #1

Share This Page