下面的代码我用于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