为什么Android密钥(api密钥)无效或该密钥已被GCM服务器弃用? [英] Why Android key (api key) is invalid or that key is deprecated by GCM server?

查看:266
本文介绍了为什么Android密钥(api密钥)无效或该密钥已被GCM服务器弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两年前(2014年6月),我为Android应用程序创建了GCM推送通知的Android API密钥。从最近两天起,GCM服务器以PHP方式返回Unauthorized(401)响应。



我搜索了为什么GCM服务器返回401到PHP,它提到API密钥无效。为什么Android API密钥无效?如果我为另一个应用程序创建服务器密钥,它可以正常工作。



Android API密钥是否有任何有效性(生命周期)?哪个关键是最适合GCM推送通知的?它是服务器,Android,iOS还是浏览器API密钥?并且这些密钥是否有有效期?



请给出关于这四个API密钥以及它们的生命周期的适当细节和解释。或者Android密钥已被弃用?

解决方案


API密钥是否有效/过期? / p>

SO问题。这里明确指出,API密钥没有到期。


有关这四个(服务器,androi,ios ,浏览器)
键。





  • SERVER KEY - 如果您的应用程序在服务器上运行,请创建并使用服务器密钥。不要在服务器代码之外使用此密钥。例如,不要将其嵌入到网页中。为防止配额被盗用,请限制您的密钥,以便仅允许您的服务器的源IP地址发出请求。

  • 如果您的应用程序在客户端(如Web浏览器)上运行,请创建并使用浏览器密钥。为防止您的密钥在未经授权的网站上使用,请仅允许您管理的域名。 IOS密钥如果您的应用程序在iOS设备上运行,则为iOS密钥。 Google会验证每个请求是否都来自与您指定的其中一个包标识符相匹配的iOS应用程序。应用的.plist文件包含其捆绑标识符。示例:com.example.MyApp
  • ANDROID KEY - 如果您的应用程序在Android设备上运行,请创建并使用Android密钥。为此,您需要使用该键指定应用程序的SHA1指纹和包名称。

  • 信息请查看此页面


    哪些关键字最适合GCM推送通知?

    我在使用GCM推送通知时发现了许多教程和SO问题,您需要使用 SERVER KEY



    来源




    Two years ago (June 2014), I created an Android API key for GCM Push Notification for my Android application. From the last two days, GCM server returns Unauthorized (401) response in PHP.

    I searched regarding why GCM server returns 401 to PHP, it mentioned that API key is invalid. Why is the Android API key invalid? If I create a Server key for another application, it works fine.

    Is there any validity(lifetime) for Android API key? Which key is the best for GCM push notification? Is it Server, Android, iOS or Browser API key? And do those keys have validity period or not?

    Please give the proper details and explanation about those four API keys also their lifetime. Or is Android key deprecated?

    解决方案

    Is there any validity/expiration of an API key?

    From the answer in this SO question. It is clearly stated here, that API key doesn't have expiration.

    For details and explaination about the four(server,androi,ios,browser) keys.

    • SERVER KEY - Create and use a Server key if your application runs on a server. Do not use this key outside of your server code. For example, do not embed it in a web page. To prevent quota theft, restrict your key so that requests are only allowed from your servers' source IP addresses.

    • BROWSER KEY - Create and use a Browser key if your application runs on a client, such as a web browser. To prevent your key from being used on unauthorized sites, only allow referrals from domains you administer.

    • IOS KEY - Create and use an iOS key if your application runs on iOS devices. Google verifies that each request originates from an iOS application that matches one of the bundle identifiers you specify. An app's .plist file contains its bundle identifier. Example: com.example.MyApp

    • ANDROID KEY - Create and use an Android key if your application runs on Android devices. To do so, you need to specify the SHA1 fingerprints and package names of the application using that key.

    For more information check this page.

    Which key is best for GCM push notification?

    I found many tutorials and SO questions that you need to use SERVER KEY in using GCM push notifications.

    sources

    这篇关于为什么Android密钥(api密钥)无效或该密钥已被GCM服务器弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆