下面的代碼我用於Google登錄。我在應用程序文件夾中添加了google-services.json
文件。我在根gradle module中使用classpath 'com.google.gms:google-services:2.0.0
'。我在開發者控制檯檢查了我的包,在終端上運行命令keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
得到了SHA1密鑰(我使用的是ubuntu)。我已經啓用了Google+ API。我已經創建了OAuth同意屏幕和OAuth客戶端ID。但是當我嘗試使用google登錄時出現以下錯誤 -statusCode = DEVELOPER_ERROR在谷歌登錄
{的StatusCode = DEVELOPER_ERROR,分辨率= NULL}
我檢查了類似的問題,但找不到合適的解決方案。 代碼
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestProfile().requestId()
.requestEmail().requestScopes(new Scope(Scopes.PLUS_ME))
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
googleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
} else {
// Signed out, show unauthenticated UI.
// updateUI(false);
}
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if(mGoogleApiClient.isConnected())
{
mGoogleApiClient.disconnect();
}
}
@Override
protected void onResume() {
super.onResume();
if(mGoogleApiClient.isConnected())
{
mGoogleApiClient.connect();
}
}
清單
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- To use account credentials -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
+1這裏。出於某種原因(用戶錯誤?),我的清單「com.company.appname」中的應用程序ID在我的應用程序的build.gradle文件中反轉:「company.com.appname」。糾正這個解決了我的問題。 – Zoccadoum