3

我正在为我的 Android 应用程序实施 C2DM。客户端(Android)进展顺利,但我在实现服务器端时有点困惑。

我的服务器是 C#/.NET。关于身份验证,官方文档链接到 404: https ://developers.google.com/android/c2dm/#handling_reg

我找到了另一个页面: https ://developers.google.com/accounts/docs/AuthForInstalledApps

但它说已弃用。所以,我不知道现在该怎么办。使用已弃用的功能或学习如何使用 OAuth?(以前从未这样做过)

如果我使用 OAuth - 我应该在这里传递什么: Authorization: GoogleLogin auth=[AUTH_TOKEN]

任何关于这个主题的指针将不胜感激

谷歌最近的帖子听起来像客户端登录是要走的路... http://android-developers.blogspot.com/2012/04/android-c2dm-client-login-key.html

4

3 回答 3

3

I recently started setting up C2DM myself, and I had the same confusion you did when I saw the deprecation notice. My best understanding is that while Google is moving to OAuth 2 for most services, deprecating ClientLogin, C2DM still uses ClientLogin, so that's what you have to use in this case.

Rationale:

  • Absolutely everything in the (up-to-date and frequently updated) C2DM documentation explicitly refers to ClientLogin, strongly suggesting that the service is tied to this particular authorization method. ClientLogin is explicitly mentioned 11 times, while no mention is made to OAuth or to any other possible means of authentication.

In short, I believe that you must use ClientLogin for C2DM and should ignore the fact that it is deprecated for other Google services that are better served by OAuth. It doesn't appear that anything other than ClientLogin is intended to be used with C2DM in the foreseeable future.

于 2012-06-02T02:05:20.670 回答
2

我认为 OAuth 2.0 是要走的路。我第一次使用 C2DM 的 ClientLogin,但发现没有管理颁发的授权码。即使我使用Google 帐户授权访问页面撤销访问权限,我仍然可以使用之前发布的授权码向我的设备发送消息!此外,我不喜欢将 Google 凭据存储在某处以获取授权码的想法。

OAuth 2.0 稍微复杂一些,但现在我理解了它,我发现它比 ClientLogin 优雅得多。

基本上,使用Google 的 OAuth 2.0 Playground生成OAuth Client IDOAuth Client secretRefresh Token。这些可用于获取(刷新)在有限时间(通常为 1 小时)内有效的访问令牌。然后使用访问令牌使用 C2DM 发送消息。

我按照本教程进行设置,它就像一个魅力!

于 2012-06-15T20:41:03.470 回答
0

Did you see this Java example?

http://code.google.com/p/google-api-java-client/wiki/OAuth2Draft10

It's easy to understand in my opinion.

于 2012-06-02T02:11:55.780 回答