简体   繁体   English

GCM HTTP错误401:未经授权

[英]GCM HTTP Error 401: Unauthorized

I have integrated GCM on client also made its Server side component. 我在客户端上集成了GCM,也使其成为服务器端组件。 Every thing was working fine, I was able to send push notification from server to all the registered client. 每件事情都很好,我能够从服务器向所有注册客户端发送推送通知。 I am using google App engine as my server. 我使用谷歌App引擎作为我的服务器。

Problem came when: 出现问题:

  1. I changed the API Key on server. 我更改了服务器上的API密钥。
    • Earlier I was using my personal GMail account to get API Key and all other access was through my account. 之前我使用我的个人GMail帐户获取API密钥,所有其他访问都是通过我的帐户进行的。 Just before pushing the application live I moved the server to Production account and also changed the IDs as per production Ids. 在推送应用程序之前,我将服务器移动到生产帐户,并根据生产ID更改了ID。 By Id I mean API Key, project ID, Production Keystore etc. Now the issue is when I want to send Push notification on Server I am getting URL Exception "HTTP Error 401: Unauthorized" 我是指API密钥,项目ID,生产密钥库等。现在问题是我想在服务器上发送推送通知我得到URL异常“HTTP错误401:未经授权”

I tried doing: - Deleting my older Ids. 我尝试过: - 删除我的旧ID。 - Deleting Old Public API access keys. - 删除旧的公共API访问密钥。

The same code works fine if I try to send Push notification from my old Server. 如果我尝试从旧服务器发送推送通知,相同的代码工作正常。

Does it has something to do with : Project package name and API key... which gets registered once can only be used....If yes How to delete that without changing the client project package name. 它是否与某些事情有关:项目包名称和API密钥...只能使用一次注册....如果是,如何删除它而不更改客户端项目包名称。

Please help we cannot go live with Old Server. 请帮助我们不能使用Old Server。

Since this is an older question that was never answered but still gets views, I'll post here that this issue may have been obsoleted as the Cloud Console has gone through a couple of iterations since then. 由于这是一个从未得到回答但仍能获得视图的旧问题,我将在此处发布此问题可能已经过时,因为云控制台从那时起经历了几次迭代。

Also, Google Cloud Messaging has been superseded by Firebase Cloud Messaging. 此外,Google Cloud Messaging已被Firebase云消息传递所取代。 New projects should use FCM, and existing projects are encouraged to upgrade in order to benefit from new features. 新项目应使用FCM,鼓励现有项目进行升级,以便从新功能中受益。

Firebase Cloud Messaging Firebase云消息传递
https://firebase.google.com/docs/cloud-messaging/ https://firebase.google.com/docs/cloud-messaging/

Check if ports 5228-5230(GCM ports) are open in the new server. 检查新服务器中的端口5228-5230(GCM端口)是否已打开。 It could be the problem. 这可能是问题所在。

The issue can be beacause you are using the old server api key for the new server as well. 问题可能是因为您正在为新服务器使用旧的服务器api密钥。 For sending the push notification from server side, you need the api key generated with the help of server's public IP address. 要从服务器端发送推送通知,您需要在服务器的公共IP地址的帮助下生成api密钥。

If it is testing purposes, make sure your server API key on the google console has the relevant ip addresses in the whitelist: 0.0.0.0/0 ::/0 如果是测试目的,请确保Google控制台上的服务器API密钥在白名单中具有相关的IP地址:0.0.0.0/0 :: / 0

These are for ipv4 and ipv6 ips 这些是针对ipv4和ipv6 ips的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM