Android google cloud messaging -


I try to send a message from my server to Google Cloud Server, but I have a problem ... I have a server key (Key for server applications), set it to this code:

  $ headers = array ('authorization: key ='. My server key, 'content-type: application / Jason '); $ 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_RETURNTRANSFER, true); Curl_setopt ($ CH, CURLOPT_SSL_VERIFYHOST, 0); Curl_setopt ($ CH, CURLOPT_SSL_VERIFYPEER, incorrect); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, json_encode ($ fields)); $ Result = curl_xac ($ CH);   

This is the result after sending me a message:

Unauthorized error 401

I use such IPs: 78.47.150.20

But when I use the test IP 0.0.0.0/0 then I have no problem ....

  function sending notification ($ registrar array, $ messagedata) {$ apiKey = "YOUR_API_KEY"; $ Headers = array ("Content Type:". "Application / Jason", "Authorization:". "Key =". $ ApiKey); $ Data = array ('data' = & gt; $ message data, 'registration_id' = & gt; $ sign); $ Ch = curl_init (); Curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ headers); Curl_setopt ($ c, CURLOPT_URL, "https://android.googleapis.com/gcm/send"); curl_setopt ($ CH, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ CH, CURLOPT_SSL_VERIFYPEER, 0); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, json_encode ($ data)); $ Response = curl_exec ($ ch); Curl_close ($ ch); Return $ Reaction; }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -