2015-07-24 19 views
5

Tôi không thể nhận phản hồi từ GCM ngay cả khi tôi đang cung cấp khóa API máy chủ chính xác do google tạo.Lỗi trái phép GCM 401

Sự cố: Tôi muốn thực hiện thông báo đẩy bằng GCM từ ứng dụng buồm của tôi. tôi gửi bài dưới mã để "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"] 
} 

Mã số: 2

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

tôi nhận được câu trả lời như sau.

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

Trả lời

2

Tiêu đề phải là tiêu đề HTTP, không phải là phần tử trong tải trọng.

+0

bạn có thể cung cấp ví dụ làm việc không? – DebuggerCoder

+0

Ví dụ ở đây phải phù hợp hơn với những gì bạn muốn đạt được: http://code.runnable.com/U4kVi8yKO58ptG0l/%5Bandroid-api%5D-gcm-send-using-node-js –

+0

@DebuggerCoder curl -X POST - -header "Content-Type: application/json" - tiêu đề "Cấp phép: khóa = AIzaXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "https://android.googleapis.com/gcm/send" --data-ascii '{"thông báo": {"nội dung ":" yyy "}," tới ":" XXXXXXXXXX: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZZZZZZZZ "} ' – TheWonderBird

0

Đảm bảo bạn đã bật đúng API trong Cloud Console. Nếu gửi bằng khóa API máy chủ, bạn cần bật "Google Cloud Messaging cho Android".

A screenshot from Cloud Console

Các vấn đề liên quan