PlayGames ERROR_INVALID_CREDENTIAL
Posted
技术标签:
【中文标题】PlayGames ERROR_INVALID_CREDENTIAL【英文标题】: 【发布时间】:2019-08-29 21:01:49 【问题描述】:我正在尝试将我的应用程序中的 PlayGames 登录服务与 firebase 一起使用,但是当我这样做时,总是会出现此错误:
“com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: 提供的身份验证凭据格式不正确或已过期。"
异常错误:
提供的身份验证凭据格式不正确或已过期。 [ 失败 从https://www.googleapis.com/games/v1/players/me 获取资源, http状态:403,http响应:“错误”:“错误”:[“域”: “全局”,“原因”:“禁止”,“消息”:“禁止”],“代码”: 403, "消息": >"禁止" ]
我的代码:
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestServerAuthCode("xxx.apps.googleusercontent.com", true)
.build();
GoogleSignInClient signInClient = GoogleSignIn.getClient(this, gso);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN)
Task < GoogleSignInAccount > task = GoogleSignIn.getSignedInAccountFromIntent(data);
try
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithPlayGames(account);
catch (ApiException e)
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
private void firebaseAuthWithPlayGames(GoogleSignInAccount acct)
mAuth = FirebaseAuth.getInstance();
FirebaseUser currentUser = mAuth.getCurrentUser();
AuthCredential credential = PlayGamesAuthProvider.getCredential(acct.getServerAuthCode());
Log.d(TAG, "firebaseAuthWithPlayGames4:" + acct.isExpired());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener < AuthResult > ()
@Override
public void onComplete(@NonNull Task < AuthResult > task)
if (task.isSuccessful())
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
else
//here get the exception error always
Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
);
什么意思是畸形?,我必须在凭证中添加更多信息?
【问题讨论】:
【参考方案1】:好的,我解决了错误:
1- 我使用了不正确的变量“DEFAULT_SIGN_IN”。我不得不将其更改为“DEFAULT_GAMES_SIGN_IN”(在此之后,我收到 12501 错误,但通过后续步骤解决了)
2- 我必须在 androidManifest.xml 的 Application 标签中添加这两行:
<application ....>
<meta-data android: name = "com.google.android.gms.games.APP_ID" android: value = "@ string / app_id" />
<meta-data android: name = "com.google.android.gms.version" android: value = "@ integer / google_play_services_version" />
</ application>
3- 我必须在 string.xml 中添加我的 APP ID:
<string name = "app_id"> xxxxxx815210 </ string>
应用 ID 位于您的 google 控制台-> 游戏服务-> 您已发布的服务,位于顶部(在游戏标题下)
完成这 3 个步骤后,应用可以连接到 Play 游戏服务。
【讨论】:
以上是关于PlayGames ERROR_INVALID_CREDENTIAL的主要内容,如果未能解决你的问题,请参考以下文章