收到 id 和 auth token 后发送消息时出现 c2dm 401 错误
我见过很多类似的问题,但尽管其中一些被接受,但没有好的答案。 我已经注册了C2DM。我收到了确认电子邮件。然后我编写了一些简单的应用程序来注册 C2DM。我得到了 id(在模拟器和真实设备上尝试过)。然后,我获得了用于 C2DM 注册的电子邮件的身份验证令牌(带有curl)(与我在应用程序中用于获取 id 的电子邮件相同)。
当我尝试进行推送(也使用curl)时,我收到 401 错误(就像身份验证令牌错误一样)。
我读了很多教程,但我已经没有想法了。
I have seen many similiar questions but no good answer despite some of them being accepted.
I have registered for C2DM. I received confirmation email. Then I wrote some simple app to register for C2DM. I get the id (tried on emulator and on real device). Then I got the auth token (with curl) for my email that I used for C2DM registration (the same email that I use in app for acquiring the id).
When I try to do the push (also with curl), I get 401 error (like the auth token is wrong).
I read many tutorials and I am running out of ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我尝试一下(仅使用curl):
首先我们正在申请身份验证令牌:
curl.exe -v -k https://www.google.com/accounts/ClientLogin -d [email protected] -d Passwd=secret -d accountType=GOOGLE -d source=your.registered.domain -d service=ac2dm
在结果中你是接收身份验证令牌:
< HTTP/1.1 200 正常
SID=XXX
LSID=XXX
验证=XXX
* 连接 #0 到主机 www.google.com 保持不变
* 关闭连接#0
* SSLv3、TLS 警报、客户端问候 (1):
请注意,结果中的 Auth 响应首字母大写:“Auth=XXX”!
现在我们将结果用于下一个请求,但首字母小写:
curl.exe -v -k --header "授权:GoogleLogin auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -dcollapse_key=Z
这有效!但是,如果您使用第一个响应中的身份验证(“Auth”中的大写 A),您会收到 401 错误:
curl.exe" -v -k --header "Authorization: GoogleLogin Auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -dcollapse_key=Z
所以请求 2 的“auth”区分大小写,我认为这是 50% 的用户正在陷入的陷阱,希望有所帮助。
Let me try it (with curl only):
At first we are applying for the auth token:
curl.exe -v -k https://www.google.com/accounts/ClientLogin -d [email protected] -d Passwd=secret -d accountType=GOOGLE -d source=your.registered.domain -d service=ac2dm
In the result your are receiving the auth token:
< HTTP/1.1 200 OK
SID=XXX
LSID=XXX
Auth=XXX
* Connection #0 to host www.google.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
Please note that the Auth response is in the result with an uppercase first letter: "Auth=XXX"!
Now we are using the result for the next request but with lowercase first letter:
curl.exe -v -k --header "Authorization: GoogleLogin auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z
And this works! But you are getting a 401 error, if you are using the auth like in the first response (upper case A in "Auth"):
curl.exe" -v -k --header "Authorization: GoogleLogin Auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z
So the "auth" of request 2 is case sensitive. I think this is a pitfall 50% of the users are stepping into. Hope that helps.
也许这就是问题所在?
http://groups.google.com/group/vogella/browse_thread/thread/95865344e6d2c734
一般来说,您在 Android 设备上指定的“sender”参数必须相同注册为发件人的电子邮件地址(服务器端)。
Maybe this is the problem?
http://groups.google.com/group/vogella/browse_thread/thread/95865344e6d2c734
Basucally, the "sender" parameter that you specifiy on teh Android device must be the same email address that is registred as the sender (server-side).