Problems with push notification

99 views
Skip to first unread message

zonar...@gmail.com

unread,
Dec 7, 2016, 1:34:58 PM12/7/16
to Firebase Google Group
Good morning, I'm starting with an android application and I use a web page in php and js, I try to send a push notification and it gives me the following error.

"XMLHttpRequest can not load https://fcm.googleapis.com/fcm/send. Response to preflight request does not pass access control check: In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost' is therefore not allowed access."

Check in other forums and see the proposed solutions on modifying the .httacces or lines in php.

I leave the lines of code.

// API access key from Google API's Console
Define ('API_ACCESS_KEY', 'key');


$ RegistrationIds = array ('tonken');

// prep the bundle
$ Msg = array
(
'Message' => 'here is a message. Message '
'Title' => 'This is a title. Title ',
'Subtitle' => 'This is a subtitle. Subtitle ',
'TickerText' => 'Ticker text here ... Ticker text here ...'
'Vibrate' => 1,
'Sound' => 1,
'LargeIcon' => 'large_icon',
'SmallIcon' => 'small_icon'
);

$ Fields = array
(
'Registration_ids' => $ registrationIds,
'Data' => $ msg
);

$ Headers = array
(
'Authorization: key ='. API_ACCESS_KEY,
'Content-Type: application / json'
'Access-Control-Allow-Origin: *'
);

$ 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_SSL_VERIFYPEER, false);
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, json_encode ($ fields));
$ Result = curl_exec ($ ch);
Curl_close ($ ch);

Echo $ result;


You could send me an example because everything I did did not work.

From already thank you very much.

Gerardo Tezza
Reply all
Reply to author
Forward
0 new messages