gpt4 book ai didi

java - 在 Android 上设置谷歌登录时出现 "FirebaseError: Invalid authentication credentials provided"错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:31:53 34 4
gpt4 key购买 nike

我一直在尝试为我的应用设置谷歌登录。

我按照这里的教程:

https://developers.google.com/identity/sign-in/android/start-integrating

我做了一切。我可以登录登录和退出登录。

然后我添加了一个异步任务来获取 token ,它似乎已成功检索。它的实现如下:

private class GetIdTokenTask extends AsyncTask<Void, Void, String> {


private static final String SERVER_CLIEdNT_ID = "749433126040-ca4gfj7ucuh0m2suo3230u03o3d7doni.apps.googleusercontent.com";

@Override
protected String doInBackground(Void... params) {

String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String scopes = "audience:server:client_id:" + SERVER_CLIEdNT_ID; // Not the app's client ID.
try {
return GoogleAuthUtil.getToken(getApplicationContext(), account, scopes);
} catch (IOException e) {
Log.e(TAG, "Error retrieving ID token.", e);
return null;
} catch (GoogleAuthException e) {
Log.e(TAG, "Error retrieving ID token. Google exception", e);
return null;
}
}

@Override
protected void onPostExecute(String result) {
Log.i(TAG, "ID token: " + result);
if (result != null) {

idToken = result;

Toast.makeText(context, "token is " + result, Toast.LENGTH_LONG).show();


} else {
// There was some error getting the ID Token
// ...
Toast.makeText(context, "token is null", Toast.LENGTH_LONG).show();
}
}

}

所以在运行该方法并获取 token 后,我运行通用的 firebase 代码以连接到 Firebase(已经设置了一个谷歌应用程序,将客户端 ID 放入 firebase,启用它等)我从https://www.firebase.com/docs/android/guide/login/google.html

并实现如下:

 public void loginFireBase() {


Firebase ref = new Firebase("https://boiling-fire-944.firebaseio.com");
ref.authWithOAuthToken("google", idToken, new Firebase.AuthResultHandler() {


@Override
public void onAuthenticated(AuthData authData) {
// the Google user is now authenticated with your Firebase app

Toast.makeText(context, "user succesfully authenticated with firebase", Toast.LENGTH_LONG).show();
Toast.makeText(context, idToken, Toast.LENGTH_LONG).show();
}

@Override
public void onAuthenticationError(FirebaseError firebaseError) {
///////THIS IS THE PART WHERE THE ERROR IS GENEREATED FROM//////////

Log.v("firebase problem", firebaseError.toString());
Toast.makeText(context, "I'm an authenticated error" + "id Token was " + idToken, Toast.LENGTH_LONG).show();


}
});
}

}

所以最终,我登录,我得到一个 token ,然后将它传递给 firebase authWithOAuthToken 方法,然后我得到错误:

FirebaseError: Invalid authentication credentials provided.

有人能看出我的代码有什么问题吗?我感觉 token 无效,但找不到检查其有效性的方法。

如果您需要我发布更多信息,请告诉我,我尽量保持简短。

感谢任何可以提供帮助的人!

最佳答案

每当我需要在 Android 上使用 Firebase 进行身份验证时,我都会返回到 Firebase Android login demo .这是该应用程序的方式 gets the OAuth token for Google authentication :

String scope = String.format("oauth2:%s", Scopes.PLUS_LOGIN);
token = GoogleAuthUtil.getToken(
GoogleOAuthActivity.this,
Plus.AccountApi.getAccountName(mGoogleApiClient),
scope);

看起来你得到了 cross-client id for the user ,这不是有效的 OAuth token 。

更新 (20160308):现在我改为查看 FirebaseUI library ,其中包括此功能并且是最新的。

关于java - 在 Android 上设置谷歌登录时出现 "FirebaseError: Invalid authentication credentials provided"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31210402/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com