问题描述
我想验证我的android应用蒙山的oauth2 protocole的用户,以便用户并不需要创建一个登录名和密码我的应用程序。
要做到这一点,我按照下面的教程:的
我已经导入谷歌播放服务SDK示例(在AndroidSDK \演员\谷歌\ google_play_services \样本\ AUTH),我有改变的范围值。
不过,我不设法获得身份验证令牌......虽然我已经正确配置我的谷歌控制台API。
下面的函数调用为gettoken方式:
保护字符串fetchToken()抛出IOException异常{
尝试 {
返回GoogleAuthUtil.getToken(mActivity,mEmail,mScope);
}赶上(GooglePlayServicesAvailabilityException playEx){
// GooglePlayServices.apk要么是老了,但禁用或不present。
mActivity.showErrorDialog(playEx.getConnectionStatus code());
}赶上(UserRecoverableAuthException userRecoverableException){
//无法验证,但用户可以解决这个问题。
//转发用户到适当的活性。
mActivity.startActivityForResult(userRecoverableException.getIntent(),mRequest code);
}赶上(GoogleAuthException fatalException){
onError的(不可恢复的错误+ fatalException.getMessage(),fatalException);
}
返回null;
}
和这里是我的范围:观众:服务器:CLIENT_ID:MY_CLIENT_ID.apps.googleusercontent.com
当我尝试了,我得到以下异常:
08-16 17:22:08.471:E / TokenInfoTask(16546):异常:
08-16 17:22:08.471:E / TokenInfoTask(16546):com.google.android.gms.auth.GoogleAuthException:未知
08-16 17:22:08.471:E / TokenInfoTask(16546):在com.google.android.gms.auth.GoogleAuthUtil.getToken(来源不明)
您应该使用Google+登录功能,其中谷歌2月份发布的,因为这将让你跨客户端授权和访问更多的数据,您可以使用个性化您的应用程序。在幕后,此授权库使用的OAuth 2连接到谷歌服务。
某些资源,让你开始:
- 的 Google+的Android的快速启动应该让你去一个基本的实现。
- 如果您有任何问题,最常见的是包括在风险完全失败的博客文章的 问题
- 如果你想看到一个完整的前端到后端的整合,你可以看看 PhotoHunt
- 的 Google+的标签堆栈溢出标记有多达最新的信息和支持,以及
I wish to authenticate users of my android application whith the oauth2 protocole, so as to the user don't need to create a login and password for my app.
To do that, I follow the following tutorial : http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html
I've import the google play service sdk sample (in AndroidSDK\extras\google\google_play_services\samples\auth), and I have change the scope value.
However, I don't manage to get authentication token... While I've correctly configure my google console API.
Here is the function calling getToken method :
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (GooglePlayServicesAvailabilityException playEx) {
// GooglePlayServices.apk is either old, disabled, or not present.
mActivity.showErrorDialog(playEx.getConnectionStatusCode());
} catch (UserRecoverableAuthException userRecoverableException) {
// Unable to authenticate, but the user can fix this.
// Forward the user to the appropriate activity.
mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
} catch (GoogleAuthException fatalException) {
onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
}
return null;
}
And here is my scope : audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com
When I try that, I get the following exceptions :
08-16 17:22:08.471: E/TokenInfoTask(16546): Exception:
08-16 17:22:08.471: E/TokenInfoTask(16546): com.google.android.gms.auth.GoogleAuthException: Unknown
08-16 17:22:08.471: E/TokenInfoTask(16546): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
You should be using Google+ Sign-In, which Google released in February, because this will get you cross-client authorization and access to more data that you can use to personalize your app. Behind the scenes, this authorization library uses OAuth 2 to connect to Google services.
Some resources to get you started:
- The Google+ Android Quick Start should get you going with a basic implementation.
- If you have any issues, the most common ones are covered in the Risk Complete Failure blog post Common Problems with Sign-in on Android
- If you want to see a full front-end to back-end integration, you can look at PhotoHunt
- The Google+ tag on Stack Overflow tag has up-to-date information and support as well
这篇关于谷歌游戏服务认证(OAuth的2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!