我正在使用Firebase开发googleSignIn
我的app-build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
// applicationID,sdk version etc
}
buildTypes {
// release, debug etc
}
}
dependencies {
// other dependencies
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
}
和我的project-build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的signInButton
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_activity_google_sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
我的java代码
findViewById(R.id.sign_in_activity_google_sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(SignInActivity.this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Misc.REQUEST_CODE_GOOGLE_SIGN_IN);
}
});
和onActivityResult
if (requestCode == Misc.REQUEST_CODE_GOOGLE_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.e("signInResult:name", account.getDisplayName());
} catch (ApiException e) {
Log.e("signInResult:failed", "code=" + e.getStatusCode());
Misc.showAlert(SignInActivity.this, "Google Sign in", e.getLocalizedMessage());
}
}
我尽了最大努力按照他们在firebase docs [here]中所说的那样做,但是似乎有些工作不正确,因为我总是在响应代码中遇到异常10
,通过搜索我发现这可能是由配置,我的项目是在firebase应用中设置的,而且我非常确定应该没问题,因为如果我尝试执行signInWithEmailAndPassword
该功能,但由于GoogleSignIn
它似乎不起作用,我们将不胜感激,谢谢
确保在两种环境下都设置了sha键(发布和调试)
您可以运行此命令以获取sha键,
发布
keytool -exportcert -list -v \-alias <your-key-name> -keystore <path-to-production-keystore>
然后为调试键
keytool -list -v \-alias androiddebugkey -keystore ~/.android/debug.keystore(password for debug keystore is >>>>android<<<)
确保在您的Firebase项目中同时包含这两个代码,我相信您输入的错误sha
或者丢失了其中之一
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句