Dor*_*ori 7 android firebase google-signin
我正在尝试在我的Android应用中检索已登录用户的联系人电子邮件列表.从这里的教程开始,以下行:
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Run Code Online (Sandbox Code Playgroud)
导致Android Studio错误"GoogleSignIn被标记为内部,不应从应用访问".
该项目编译,但当我尝试登录时,logcat输出:
W/GooglePlayServicesUtil: Google Play services out of date. Requires 12210000 but found 11947470
Run Code Online (Sandbox Code Playgroud)
我的app/gradle.build包含:
dependencies {
...
implementation 'com.google.android.gms:play-services-auth:12.0.0'
implementation 'com.google.firebase:firebase-core:12.0.0'
implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
当我对Firebase发表评论时:
dependencies {
...
implementation 'com.google.android.gms:play-services-auth:12.0.0'
//implementation 'com.google.firebase:firebase-core:12.0.0'
//implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
//apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
我没有收到错误并成功登录.
我想将Firestorm集成到我的应用程序中,是否需要重新设计登录过程?如果是这样,怎么样?
重现,这是我的MainActivity.通过编译Firebase,Log.w调用输出signInResult:failed code=12500:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
static final int RC_SIGN_IN = 1000;
GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
}
@Override
public void onClick(View v) {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
} catch (ApiException e) {
Log.w("signInResult:failed code=" + e.getStatusCode());
}
}
}
Run Code Online (Sandbox Code Playgroud)
和我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.XXX.MainActivity">
<com.google.android.gms.common.SignInButton
android:id="@+id/google_sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
https://developers.google.com/android/guides/releases
版本12.0.0的已知问题
...
- 注释会导致虚假的lint错误,声称GoogleSignIn和CredentialsClient仅限内部使用.这些可以安全地被忽略.
| 归档时间: |
|
| 查看次数: |
789 次 |
| 最近记录: |