GCM HTTP 401授权错误 [英] GCM http 401 authorization error

查看:682
本文介绍了GCM HTTP 401授权错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的后端服务器发送POST请求GCM服务器,我得到一个授权错误HTTP 401。

我跟这里介绍的步骤:

<一个href="http://developer.android.com/google/gcm/http.html#auth_error">http://developer.android.com/google/gcm/http.html#auth_error

 &GT;&GT; API_KEY = AIzaSyDEy3 ...

&GT;&GT;卷曲--header授权:键= $ API_KEY--header内容类型:应用/ JSON的https://android.googleapis.com/gcm/send -d{\registration_id \:\ABC \}
 

我得到这样的:

 &LT; HTML&GT;
&其中; HEAD&GT;
&LT; TITLE&GT;未授权&LT; / TITLE&GT;
&LT; / HEAD&GT;
&LT; BODY BGCOLOR =#FFFFFFTEXT =#000000&GT;
&LT; H1&GT;未授权&LT; / H1&GT;
&LT; H2&GT;错误401&LT; / H&GT;
&LT; / BODY&GT;
&LT; / HTML&GT;
 

在排除故障,它说:

 验证错误
那你想用它来发送邮件的发件人帐户无法进行身份验证。可能的原因有:
    1.授权头缺失或无效的语法。
    2.无效的项目数量将作为重点。
    3.输入有效的,但与GCM服务被禁用。
    4.要求源自于服务器密钥的IP白名单中没有一台服务器。
 

我想过这问题:

  1. 是卷曲的请求是否正确?
  2. 标题
  3. 请他们的意思是API_KEY(AIzaSy ...)或类似8305134的项目数量...。?
  4. 如何加入白名单我的服务器密钥的IP?
  5. 如果我运行curl命令,我必须列入白名单我的电脑的IP地址?
解决方案
  

难道他们的意思是API_KEY(AIzaSy ...)或类似8305134的项目数量...。?

这意味着,应该在袅袅的脚本添加的服务器密钥。项目编号不应该被用来发送消息在服务器端。版

要创建新的服务器密钥,按照步骤,

  • 转到 https://cloud.google.com/console/project
  • 点击您的项目
  • 转到的API和放大器; AUTH 在左面板
  • 在子菜单中选择凭据左面板
  • 公开的API访问,点击创建新密钥
  • 选择服务器
  • 在接下来的对话框中,指定IP地址白名单,如果您有任何。保留为空时,请求将来自任何IP
  • 点击创建
  • 您会发现新的服务器密钥下创建公开API访问

这关键是要用来发送邮件的脚本在服务器端。

  

我如何加入白名单我的服务器密钥的IP?

您可以白名单在创建服务器密钥。

  

如果我运行curl命令,我必须列入白名单我的电脑的IP地址?

有关测试的目的,你没有指定IP。对于商业用途,你可能想。

警告 IP设置为 0.0.0.0/0 中提到的的入门的指南将允许所有的IPv4地址,而不是IPv6的。

When my backend server sends post requests to GCM servers I get an authorization error HTTP 401.

I followed the steps described here:

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\"}"

I get this:

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

In the troubleshooting it says:

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.

I have questions about that:

  1. Is the header in the curl request correct?
  2. Do they mean "api_key" (AIzaSy…) or the Project number like 8305134….?
  3. How do I whitelist my Server Key IP?
  4. If I'm running the curl command, do I have to whitelist the IP-Address of my computer?

解决方案

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

It means Server key which should added in your curl script. The project number should not be used for sending message on server side.

To create the new server key, follow the steps,

  • Go to https://cloud.google.com/console/project
  • Click your Project
  • Go to APIs & auth on Left Panel
  • Select Credentials in submenu on Left Panel
  • Under Public API access, click on "Create New Key"
  • Choose 'Server'
  • On next dialog, Specify the whitelisted IPs, if you have any. Leaving it blank, the requests will be from any IP
  • Click Create.
  • You will find the new server key is created under "Public API Access"

This key is to be used for sending message in your script on server side.

How do I whitelist my Server Key IP?

You can whitelist while creating server key.

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

For testing purpose, you dont have to specify the IP. For commercial purpose, you may want to.

Warning setting IP to 0.0.0.0/0 as mentioned in the Getting Started guide will allow all IPv4 address, but not IPv6.

这篇关于GCM HTTP 401授权错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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