Android 如何从谷歌获取 api 密钥以进行推送通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20674535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:15:43  来源:igfitidea点击:

How to get api key from google for push notification

androidpush-notificationapi-key

提问by Sandesh Sharma

I have followed thistutorial for android push notification. I am not getting services-> api access menu and api key. How to get API key? The UI is not showing API key, I have created the project too.

我已经按照教程进行了 android 推送通知。我没有得到服务-> api 访问菜单和 api 密钥。如何获取API密钥?UI 没有显示 API 密钥,我也创建了该项目。

采纳答案by Eran

You used an old tutorial that describes the old UI of Google APIs. In the new UI you need to do the following (source):

您使用了描述 Google API 旧 UI 的旧教程。在新的 UI 中,您需要执行以下操作(来源):

To obtain an API key:

1. In the sidebar on the left, select APIs & auth > Registered apps.
2. Click Register app.
3. In the Name field, type your app's name.
4. Click Android > Accessing APIs directly from Android.
5. Under Android identification, type the package name for your app.
6. Enter an SHA1 fingerprint. To get this value, follow the instructions in the 
   console help.
7. Click Register.
8. In the new page, open the Android Key section and copy the API key. You will
   need the API key later on to perform authentication in your application server.

Note: If you need to rotate the key, click the "recycle key" icon. A new key will be created. If you think the key has been compromised and you want to delete it immediately, you can accomplish this by deleting the app from the console. Then create a new entry for the app with the same SHA1 and package name.

获取 API 密钥:

1. In the sidebar on the left, select APIs & auth > Registered apps.
2. Click Register app.
3. In the Name field, type your app's name.
4. Click Android > Accessing APIs directly from Android.
5. Under Android identification, type the package name for your app.
6. Enter an SHA1 fingerprint. To get this value, follow the instructions in the 
   console help.
7. Click Register.
8. In the new page, open the Android Key section and copy the API key. You will
   need the API key later on to perform authentication in your application server.

注意:如果您需要轮换密钥,请单击“回收密钥”图标。将创建一个新密钥。如果您认为密钥已泄露并想立即删除它,您可以通过从控制台删除应用程序来完成此操作。然后使用相同的 SHA1 和包名称为应用程序创建一个新条目。

To get the SHA1 fingerprint in step 6 you can use the command:

要在步骤 6 中获取 SHA1 指纹,您可以使用以下命令:

keytool -exportcert -alias androiddebugkey -keystore C:\Users\myusername\.android\debug.keystore -list -v

keytool -exportcert -alias androiddebugkey -keystore C:\Users\myusername\.android\debug.keystore -list -v

(and enter the default password androidat the prompt)

(并android在提示处输入默认密码)

回答by SaurabhJinturkar

You can generate api key by visiting https://cloud.google.com/console. You need to activate api for Google Cloud Messaging Service.

您可以通过访问https://cloud.google.com/console生成 api 密钥。您需要为 Google Cloud Messaging Service 激活 api。

Also there is provision for limiting ip addresses to connect to your api. Your ip address is provided by default. You may need to remove that to use GCM using above tutorial.

还提供了限制 ip 地址以连接到您的 api 的规定。默认提供您的 IP 地址。您可能需要删除它才能使用上述教程使用 GCM。

For more help: check this

如需更多帮助:检查

回答by Ajeesh

Try to visit this link without redirecting to new cloudGCM. This link will redirect to new google could but you need to click go backoption to see API access menu. You will see the Message like Welcome to the new Google Developers Console! Prefer the old console? Go back | Dismiss.

尝试访问此链接而不重定向到新的云GCM。此链接将重定向到新的 google can,但您需要单击返回选项以查看 API 访问菜单。您将看到类似欢迎使用新的 Google Developers Console!更喜欢旧的控制台?返回 | 解雇