[英]Error connecting to Google Play Games
好的,我正在使用Android Studio創建一個應用,並將其與Google Game Services鏈接。 但是我遇到了一個問題。
由於某些原因,我無法將我的應用連接到Google Games。 我相信我做的一切正確。 這是我目前擁有的代碼:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
這似乎陷入了無法登錄的循環中,然后試圖一次又一次地登錄。 這是我在logcat中遇到的錯誤:
GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED,
resolution=PendingIntent{e154144: android.os.BinderProxy@3787b22d}}
但是,當我刪除.addApi(Games.API)
和.addScope(Games.SCOPE_GAMES)
,游戲將完美連接到Google Plus!
首先,我創建了兩個客戶ID。 一種用於調試,另一種用於發布。 SHA1指紋正確。 我已經檢查並確認它們都匹配。 兩者都啟用了深層鏈接。 我已將我的gmail添加為測試人員。 :)當我檢查Google Developer Console時,它說有81個請求被調用,而70個失敗。 但是,它不會告訴我哪些失敗,也不會告訴他們如何修復。 我還添加了所有元數據標簽。
請幫忙,問我任何我不清楚的問題。 謝謝傑克遜·韋爾奇
更新: onActivityResult()
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
retryConnecting();
break;
}
}
這是我的onConnectionFailed方法
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// Show a localized error dialog.
GooglePlayServicesUtil.getErrorDialog(
result.getErrorCode(), this, 0, new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
retryConnecting();
}
}).show();
return;
}
// If there is an existing resolution error being displayed or a resolution
// activity has started before, do nothing and wait for resolution
// progress to be completed.
if (mIsInResolution) {
return;
}
mIsInResolution = true;
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
retryConnecting();
}
}
確保正確處理連接失敗 。 請注意onConnectionFailed()
示例:
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
這樣可以確保當您收到諸如SIGN_IN_REQUIRED
的錯誤(碰巧具有result.hasResolution() == true
,您將啟動解決該錯誤所需的適當活動(即,顯示登錄提示)。
我解決了這個問題。 我使用了舊的Google Developer Console,而舊的無法使用。 在新項目中重新創建了該項目,並且效果很好! 謝謝你們的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.