Sukhpal Singh
Sukhpal Singh

Reputation: 555

Display image in push notification on web using FCM?

I have integrated push notification in my project. Here is code from where I am sending notifications:

define( 'API_ACCESS_KEY', 'Access_key' );
        $data = array("to" => 'token',
                      "notification" => array( "title" => 'title', "body" => 'message', "icon" => '/account/images/test.png', "click_action" => 'redirect_url', ));                                                                    
        $data_string = json_encode($data);
        $headers = array
        (
             'Authorization: key=' . API_ACCESS_KEY, 
             'Content-Type: application/json'
        );                                                                                 

        $ch = curl_init();  

        curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );                                                                  
        curl_setopt( $ch,CURLOPT_POST, true );  
        curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
        curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);                                                                  

        $result = curl_exec($ch);

        curl_close ($ch);

This code is working properly but here problem is that image is not displaying in notification. I don't why. Where is a problem, how can I display image in notification?

Upvotes: 0

Views: 3632

Answers (1)

Sukhpal Singh
Sukhpal Singh

Reputation: 555

I found the mistake, I am giving icon url as http://www.example.com while icon url always require a secure URL like https://www.example.com. Due to insecure url, it is not showing icon in notifications.

Upvotes: 2

Related Questions