1

I am using curl to send a GCM push notification. My code is similar to the answer in this question: GCM with PHP (Google Cloud Messaging) Now as a response (in the code $result) I get a JSON if its successful:

{"message_id":7575959326758153703}

And and HTML if there is an error:

<HTML>
<HEAD>
    <TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <H1>Unauthorized</H1>
    <H2>Error 401</H2>
</BODY>
</HTML>

How do I parse the error messages in PHP?

Community
  • 1
  • 1
  • You could use the hhtp response code. If its 200 parse the json, else parse the HTML. But that is not the right way. Refer other answers in the link you have given. They have handled the exceptions. Also this might help you https://developers.google.com/cloud-messaging/http – Sanath Ballal Dec 30 '15 at 08:17
  • @Viktor I would suggest that you try the solution offered here http://stackoverflow.com/questions/24939326/php-curl-request-data-return-in-application-json to make both response as JSON – goblin Dec 30 '15 at 12:40

0 Answers0