Unauthorized when calling Google GCM

后端 未结 2 1668
南笙
南笙 2020-12-10 07:00

I trying to use Google GCM for sending push notifications. But get a WebException that says that the remote server returns 401 unautorized. I can\'t foung why it doen\'t wor

相关标签:
2条回答
  • 2020-12-10 07:47

    Daniel - Dude there is an issue with the GCM documentation ! Use Browser key as the authorization key at the place of Server API key . It will work.

    0 讨论(0)
  • 2020-12-10 07:47

    OK, i am just shooting in the dark here. Take a look at this line:

    Request.Headers.Add(HttpRequestHeader.Authorization, "Authorization: key=AIzaSyCEygavdzrNM3pWNPtvaJXpvW66CKnjH_Y");
    

    Shouldn't it be:

    Request.Headers.Add(HttpRequestHeader.Authorization, "key=AIzaSyCEygavdzrNM3pWNPtvaJXpvW66CKnjH_Y");
    

    Since you're telling it this is a Authorization header, there's no need to add 'Authorization: ' again, does it?

    Also, make sure the string constant 'HttpRequestHeader.Authorization' is 'Authorization'.

    0 讨论(0)
提交回复
热议问题