Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM Unauthorized Error 401

I'm not able to get response from GCM even i'm providing correct server API key generated by google.

Problem : I want to make a push notification using GCM from my sails app. I'm posting below code to "https://android.googleapis.com/gcm/send"

Code : 1

{
  "headers":{
    "Content-Type":"application/json",
    "Authorization":"key=xxxxxxxxxxxxxxxxxxxx"
  },
 "notification":{
   "title":"Hello Notify",
   "text":"Notification By Sails"
 },
 "registration_ids":["xxxxxxxxxxxx","xxxxxxxxxxxx","xxxxxxxxxxxx"]
}

Code : 2

{
  "headers":{
    "Content-Type":"application/json",
    "Authorization":"key=xxxxxxxxxxxxxxxxxxxx"
  },
 "body":{
   "notification":{
      "title":"Hello Notify",
      "text":"Notification By Sails"
    }
  },
 "registration_ids":["xxxxxxxxxxxx","xxxxxxxxxxxx","xxxxxxxxxxxx"]
}

I'm getting response as below.

"statusCode": 401,
"body": "<HTML>\n
           <HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n
           <BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n
               <H1>Unauthorized</H1>\n
               <H2>Error 401</H2>\n
           </BODY>\n
         </HTML>\n",
like image 727
DebuggerCoder Avatar asked Oct 30 '22 23:10

DebuggerCoder


1 Answers

The headers should be HTTP headers, not element in the payload.

like image 162
Mickaël Rémond Avatar answered Dec 06 '22 19:12

Mickaël Rémond