使用 Android AccountManager 获取 gdata 的 authtoken
所以我试图同步到谷歌文档,而不必询问用户的凭据。我使用此代码来获取身份验证令牌:
AccountManager mgr = AccountManager.get(activity);
authToken = mgr.blockingGetAuthToken(account, DocsService.DOCS_SERVICE, true);
这将返回一个看起来格式良好的身份验证令牌。因此,在我的 DocsService 上我运行:
service.setAuthSubToken(authToken);
但是,当我尝试使用 API 时,我只是得到一个 AuthenticationException。关于如何解决这个错误有什么想法吗?
编辑:我确实拥有 USE_CREDENTIALS 权限。
So I am trying to sync to google docs, without having to ask the user for his credentials. I use this code to get an auth-token:
AccountManager mgr = AccountManager.get(activity);
authToken = mgr.blockingGetAuthToken(account, DocsService.DOCS_SERVICE, true);
This returns a auth-token that looks well-formated. So on my DocsService I run:
service.setAuthSubToken(authToken);
However, when I try to use the API I just get a AuthenticationException. Any ideas on how to approach this error?
edit: I do have the USE_CREDENTIALS permission.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是返回的令牌是 ClientLogin 令牌,而不是 AuthSub 令牌。更大的问题是 GData Java 客户端库并未正式支持 Android。我们最近在 GData Java 客户端库的主页上添加了一条注释,对于 Android,我们建议 适用于 Java 的 Google API 客户端库。
我想到了两个示例,它们将有助于您开始使用适用于 Java 的 Google API 客户端库:calendar-v2-atom-android-sample 和 docs-v3-atom-oauth-sample
披露:我是 GData Java 客户端库和 Java 项目的 Google API 客户端库的所有者。
The problem is that the returned token is a ClientLogin token, not an AuthSub token. An even bigger problem is that the GData Java Client library does not officially support Android. We recently added a note on the home page of the GData Java Client library that for Android we recommend Google API Client Library for Java instead.
Two samples come up mind that would be helpful for you for getting started with Google API Client Library for Java: calendar-v2-atom-android-sample and docs-v3-atom-oauth-sample
Disclosure: I am an owner of both the GData Java Client library and Google API Client Library for Java projects.
您可能还想查看 Yaniv 的 Google I/O 2011 会议幻灯片/视频,以获取有关如何访问 Android 上的 GData API 的参考。
http:// /www.google.com/events/io/2011/sessions/best-practices-for-accessing-google-apis-on-android.html
You might also want to take a look at Yaniv's Google I/O 2011 Session slides/video for reference on how to access the GData APIs on Android.
http://www.google.com/events/io/2011/sessions/best-practices-for-accessing-google-apis-on-android.html
正如 Yaniv 所解释的,Gdata Lib 在 Android 中不起作用。我浪费了好几个小时却没有任何结果。它看起来很奇怪,它是谷歌的产品,但在他们自己的平台(Android)上仍然不受支持。
不管怎样,我已经开发了一个可以在 Android 上运行的客户端库。我正在 Google Code 上管理该项目-
http://code.google.com/p/google-spreadsheet-lib- android/
你可以尝试一下。
As Yaniv explained, Gdata Lib doesn't work in Android. I wasted several hour with no result. It looks pretty weird, its Google's product and still not supported in their own platform (Android).
Anyway I have developed a Client Library which works on Android. I am managing the project on Google Code-
http://code.google.com/p/google-spreadsheet-lib-android/
You can give a try.