2015-07-24 12 views
5

Non riesco ad ottenere risposta da GCM anche se fornisco la chiave API server corretta generata da google.Errore non autorizzato GCM 401

Problema: desidero inviare una notifica push utilizzando GCM dall'app delle mie vele. Sto postando sotto il codice a "https://android.googleapis.com/gcm/send"

Codice: 1

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

Codice: 2

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

che sto ricevendo risposta, come di seguito.

"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", 

risposta

2

Le intestazioni devono essere intestazioni HTTP, non elemento nel carico utile.

+0

puoi fornire un esempio di funzionamento? – DebuggerCoder

+0

L'esempio qui dovrebbe essere più in linea con ciò che si vuole raggiungere: http://code.runnable.com/U4kVi8yKO58ptG0l/%5Bandroid-api%5D-gcm-send-using-node-js –

+0

@DebuggerCoder curl -X POST - -header "Content-Type: application/json" --header "Autorizzazione: key = AIzaXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "https://android.googleapis.com/gcm/send" --data-ascii '{"notification": {"body ":" yyy "}," a ":" XXXXXXXXXX: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZZZZZZZZ "} ' – TheWonderBird

0

Assicurarsi di aver abilitato l'API corretta in Cloud Console. Se si invia con una chiave API del server, è necessario che sia abilitato "Google Cloud Messaging per Android".

A screenshot from Cloud Console