0
我重構了我的應用包名稱。我需要登錄到我的Google適合的帳戶。但是,即使按照以下步驟進行操作,也不會成功。重構包名後Google Auth登錄RESULT_CANCELED
- 我重構了我的應用程序的包名稱。
- 我在gradle這個文件
- 我已經下載了更新谷歌服務的JSON
- 我已經在配置文件中更改了名字改變了應用程序ID。
我在我的智慧結束試圖找到解決這個問題的方法。錯誤的狀態代碼爲4.
public GoogleApiClient googleFitAuthBuild(Activity activity, GoogleApiClient.ConnectionCallbacks connectionCallbacks, GoogleApiClient.OnConnectionFailedListener failedListener) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestId()
.requestProfile()
.requestScopes(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE), new Scope(Scopes.FITNESS_BODY_READ_WRITE), new Scope(Scopes.PROFILE), new Scope(Scopes.FITNESS_NUTRITION_READ_WRITE))
.build();
return new GoogleApiClient.Builder(activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(connectionCallbacks)
.addOnConnectionFailedListener(failedListener)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.SENSORS_API)
.enableAutoManage(this, 0, failedListener)
.build();
}
public void googleApiConnect(final Activity activity, final GoogleApiClient mGoogleApiClient) {
mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
S.L("Google API connected");
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
activity.startActivityForResult(signInIntent, S.REQUEST_OAUTH);
}
@Override
public void onConnectionSuspended(int i) {
S.L("FITCONNECT suspended i=" + i);
}
});
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == S.REQUEST_OAUTH) {
if (resultCode == RESULT_OK) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount account = result.getSignInAccount();
} else if (resultCode == RESULT_CANCELED) {
S.L("RESULT_CANCELED");
}
} else {
S.L("requestCode NOT S.REQUEST_OAUTH");
}
}
輸出爲RESULT_CANCELED
。這個代碼在我重構應用程序包名稱之前正在工作。
您是否正在使用來自Google開發者控制檯的API密鑰或憑據,例如使用舊包名稱的SHA1密鑰? – noogui
是的......我設法解決了問題 – suku
你的錯誤和解決方法是什麼? – noogui