问题描述
我想添加支持href="https://developers.google.com/identity/sign-in/android/" rel="nofollow">新的谷歌登录公布为播放业务8.3.0部分。我成功地配置了项目,我越来越从GoogleApiClient令牌,但火力地堡是返回一个 无效证书错误
当调用 ref.authWithOAuthToken(谷歌,令牌)
I'm trying to add support for the new Google Sign-in announced as part of Play services 8.3.0.I successfully configured the project and I'm getting a token from the GoogleApiClient, but Firebase is returning an Invalid Credentials error
when callingref.authWithOAuthToken("google", token)
Google+登录功能的工作,但需要开发棉花糖时,这是一个痛苦的单独许可。火力地堡的android教程拥有的Google+签到样品和我的感觉是他们不'有新的谷歌支持登录在还。
Google+ sign-in is working but that requires a separate permission which is a pain when developing for Marshmallow.Firebase android tutorial has a Google+ sign-in sample and my feeling is that they dont' have support for the new Google Sign-In yet.
有没有人尝试新的谷歌登录在与火力地堡连接,并得到它的工作?
Has anyone tried the new Google Sign-In in connection with Firebase and got it to work?
推荐答案
这是的步骤组合添加登录到Android的和授权与谷歌进行的REST API 。
一旦你有一个 GoogleSignInResult
你可以从该帐户名称,然后请求令牌最小范围:
Once you have a GoogleSignInResult
you can get the account name from that and then request the token with the minimal scopes:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
String email = acct.getEmail();
// TODO: run an async task to get an OAuth2 token for the account
}
}
异步任务将需要请求这些示波器:
The async task will need to request these scopes:
protected String doInBackground(String... params) {
String scopes = "oauth2:profile email";
String token = GoogleAuthUtil.getToken(getApplicationContext(), email, scopes);
// exception handling removed for brevity
return token;
}
现在,您可以使用该令牌登录到火力地堡像往常一样:
Now you can use the token to sign in to Firebase as usual:
ref.authWithOAuthToken("google", token, new Firebase.AuthResultHandler() {...
这篇关于火力地堡和新的谷歌登录在Android上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!