gpt4 book ai didi

android - GCM http 401 授权错误

转载 作者:IT王子 更新时间:2023-10-29 00:10:51 24 4
gpt4 key购买 nike

当我的后端服务器向 GCM 服务器发送 post 请求时,我收到 HTTP 401 授权错误。

我按照此处描述的步骤操作:

http://developer.android.com/google/gcm/http.html#auth_error

>> api_key=AIzaSyDEy3...

>> curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send  -d "{\"registration_id\":\"ABC\"}"

我明白了:

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

在故障排除中它说:

Authentication Error
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
1. Authorization header missing or with invalid syntax.
2. Invalid project number sent as key.
3. Key valid but with GCM service disabled.
4. Request originated from a server not whitelisted in the Server Key IPs.

我对此有疑问:

  1. curl 请求中的 header 是否正确?
  2. 它们是指“api_key”(AIzaSy…)还是像 8305134…这样的项目编号?
  3. 如何将我的服务器 key IP 列入白名单?
  4. 如果我正在运行 curl 命令,是否必须将我的计算机的 IP 地址列入白名单?

最佳答案

Do they mean "api_key" (AIzaSy…) or the Project number like 8305134….?

这意味着应该在你的 curl 脚本中添加服务器 key 。项目号不能用于服务器端发送消息。

要创建新的服务器 key ,请按照以下步骤操作,

  • 转至 https://cloud.google.com/console/project
  • 点击您的项目
  • 转到左侧面板上的 API 和身份验证
  • 在左侧面板的子菜单中选择凭据
  • 公共(public) API 访问权限下,点击“创建新 key
  • 选择“服务器”
  • 在下一个对话框中,指定列入白名单的 IP(如果有)。将其留空,请求将来自任何 IP
  • 点击创建
  • 您会发现新的服务器 key 是在“Public API Access”下创建的

此 key 用于在服务器端的脚本中发送消息。

How do I whitelist my Server Key IP?

您可以在创建服务器 key 时加入白名单。

If I'm running the curl command, do I have to whitelist the IP-Address of my computer?

出于测试目的,您不必指定 IP。出于商业目的,您可能需要。

警告将 IP 设置为 0.0.0.0/0(如 入门 指南中所述)将允许所有 IPv4 地址,但不允许 IPv6。

关于android - GCM http 401 授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20521459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com