简体   繁体   English

Google片段getSignInIntent()返回RESULT_CANCELED

[英]Google fragment getSignInIntent() returning RESULT_CANCELED

On an Android app, I'm trying to use the Google Sign-In API to sign into a user's Google Account, so I can use the DRIVE API. 在Android应用上,我尝试使用Google登录API登录用户的Google帐户,以便可以使用DRIVE API。

GoogleSignInOptions signInOptions =
        new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .requestServerAuthCode(client_id, true)
        .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
        .build();

GoogleSignInClient client = GoogleSignIn.getClient(this, signInOptions);


// The result of the sign-in Intent is handled in onActivityResult.
startActivityForResult(client.getSignInIntent(), REQUEST_CODE_SIGN_IN);

This should be picked up by OnActivityResult. 这应该由OnActivityResult获取。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {

switch (requestCode) {
  case REQUEST_CODE_SIGN_IN:
    if (resultCode == Activity.RESULT_OK && resultData != null) {

      handleSignInResult(resultData);
    }
    break;
}

super.onActivityResult(requestCode, resultCode, resultData);
}

However, once the fragment pops up and I select an account, a resultcode of 0 (RESULT_CANCELED) is always returned in onActivityResult. 但是,一旦弹出该片段并选择了一个帐户,onActivityResult中始终返回结果代码0(RESULT_CANCELED)。 I don't know what's causing this. 我不知道是什么原因造成的。 I've included part of the stack trace below: 我在下面包括了堆栈跟踪的一部分:

03-12 10:11:14.928  9706 22776 I Authzen : [DeviceStateSyncManager] The server is in sync with current state. Nothing to do
03-12 10:11:16.425 22710 22710 D AccountChip: Account selected: 0
03-12 10:11:16.434  9701 10261 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.435  9701 10261 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.491  9701 22333 D SqlitePlayLoggerContextTable: SELECT: id=10228
03-12 10:11:16.492  9701 22333 D SqliteLogEventTable: INSERT: id=213023
03-12 10:11:16.505 22710 22743 D OpenGLRenderer: endAllActiveAnimators on 0x7876491e00 (ListView) with handle 0x78779ff860
03-12 10:11:16.519  9701 22666 D SqlitePlayLoggerContextTable: SELECT: id=10228
03-12 10:11:16.520  9701 22666 D SqliteLogEventTable: INSERT: id=213024
03-12 10:11:16.528  9701 10261 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.534  9701 10261 I chatty  : uid=10031(com.google.android.gms) Binder:9701_E identical 3 lines
03-12 10:11:16.535  9701 10261 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.537  9701  9748 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.541  9701  9748 D GoogleCertificatesImpl: isGoogleReleaseSigned: false
03-12 10:11:16.559   929 18409 D DrmHal  : found drm@1.0 IDrmFactory clearkey
03-12 10:11:16.560   929 18409 D DrmHal  : found drm@1.0 IDrmFactory default
03-12 10:11:16.561   929 18409 D DrmHal  : found drm@1.0 IDrmFactory widevine
03-12 10:11:16.562   929 18409 D DrmHal  : found drm@1.1 IDrmFactory clearkey
03-12 10:11:16.563   929 18409 D DrmHal  : found drm@1.1 IDrmFactory widevine
03-12 10:11:16.563  9701 22333 D SqlitePlayLoggerContextTable: SELECT: id=10230
03-12 10:11:16.564  9701 22333 D SqliteLogEventTable: INSERT: id=213025
03-12 10:11:16.564   767  4666 D WVCdm   : Instantiating CDM.
03-12 10:11:16.566   767  4666 I WVCdm   : [cdm_engine.cpp(480):QueryStatus] CdmEngine::QueryStatus
03-12 10:11:16.567   767 22779 I WVCdm   : [(0):] Level3 Library 4445 Apr 20 2018 14:53:46
03-12 10:11:16.584   767  4666 I WVCdm   : [oemcrypto_adapter_dynamic.cpp(575):Initialize] L3 Initialized. Trying L1.
03-12 10:11:16.585   767  4666 D         : CPPF_ServiceInitialize: start!
03-12 10:11:16.585   767  4666 D QSEECOMAPI: QSEECom_get_handle sb_length = 0x2800
03-12 10:11:16.586   767  4666 D QSEECOMAPI: App is not loaded in QSEE
03-12 10:11:16.586   767  4666 D QSEECOMAPI: app_arch = 2, total_files = 9
03-12 10:11:16.622   767  4666 D QSEECOMAPI: Loaded image: APP id = 478150660
03-12 10:11:16.625   767  4666 D         : CPPF_ServiceInitialize: end! returns 0
03-12 10:11:16.625   767  4666 D QSEECOMAPI: QSEECom_get_handle sb_length = 0x19000
03-12 10:11:16.626   767  4666 D QSEECOMAPI: App is not loaded in QSEE
03-12 10:11:16.626   767  4666 D QSEECOMAPI: app_arch = 2, total_files = 9
03-12 10:11:16.635   608  1275 W SurfaceFlinger: Attempting to set client state on removed layer: com.google.android.gms/com.google.android.gms.common.account.OriginalAccountChipAccountPickerActivity#0
03-12 10:11:16.635   608  1275 W SurfaceFlinger: Attempting to destroy on removed layer: com.google.android.gms/com.google.android.gms.common.account.OriginalAccountChipAccountPickerActivity#0
03-12 10:11:16.669   767  4666 D QSEECOMAPI: Loaded image: APP id = 478216197
03-12 10:11:16.672   767  4666 D QSAPPSVER: qsapps_get_capabilities: Capability from secure side: 0x1
03-12 10:11:16.672   767  4666 D QSAPPSVER: qsapps_get_capabilities: returns 0
03-12 10:11:16.691   644   653 D QC-time-services: Daemon: Connection accepted:time_genoff
03-12 10:11:16.691   644 22781 D QC-time-services: Daemon:Received base = 13, unit = 1, operation = 2,value = 0
03-12 10:11:16.691   644 22781 D QC-time-services: Daemon:genoff_opr: Base = 13, val = 0, operation = 2
03-12 10:11:16.691   644 22781 D QC-time-services: offset is: 1 for base: 13
03-12 10:11:16.691   644   653 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
03-12 10:11:16.691   644   653 D QC-time-services: Daemon: Connection accepted:time_genoff
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Received base = 13, unit = 1, operation = 1,value = 0
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:genoff_opr: Base = 13, val = 0, operation = 1
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon: genoff get for 13
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Value read from QTimer mseconds = 3360935727
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Value read from RTC mseconds on boot = 249831000
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Value read from QTimer mseconds = 3360935727
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Value read from generic offset = 1501749260691
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Delta read on boot mseconds = 249816257
03-12 10:11:16.691   644 22782 D QC-time-services: Daemon:Final Time = 1505360012675
03-12 10:11:16.691   644   653 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
03-12 10:11:16.703   608   710 W SurfaceFlinger: Attempting to set client state on removed layer: 
com.google.android.gms/com.google.android.gms.common.account.AccountChipAccountPickerActivity#0
03-12 10:11:16.703   608   710 W SurfaceFlinger: Attempting to destroy on removed layer: com.google.android.gms/com.google.android.gms.common.account.AccountChipAccountPickerActivity#0
03-12 10:11:16.703   767  4666 D WVCdm   : [oemcrypto_adapter_dynamic.cpp(592):Initialize] OEMCrypto_Initialize Level 1 success. I will use level 1.
03-12 10:11:16.703   767  4666 D WVCdm   : [crypto_session.cpp(646):Open] CryptoSession::Open: Lock: requested_security_level: Default
03-12 10:11:16.719   608  1275 W SurfaceFlinger: Attempting to set client state on removed layer: Dim Layer for - Task=1189#0
03-12 10:11:16.719   608  1275 W SurfaceFlinger: Attempting to destroy on removed layer: Dim Layer for - Task=1189#0
03-12 10:11:16.720   767  4666 I WVCdm   : [(0):] L3 Terminate.
03-12 10:11:16.721   767  4666 D         : CPPF_CheckMinEncLevelStatus: start!
03-12 10:11:16.721   767  4666 D         : CPPF_CheckMinEncLevelStatus: No change
03-12 10:11:16.721   767  4666 D         : CPPF_CheckMinEncLevelStatus: end!
03-12 10:11:16.721   767  4666 D QSEECOMAPI: QSEECom_dealloc_memory 
03-12 10:11:16.721   767  4666 D QSEECOMAPI: QSEECom_shutdown_app, app_id = 478216197
03-12 10:11:16.722   767  4666 D         : CPPF_ServiceUninitialize: start!
03-12 10:11:16.722   767  4666 D QSEECOMAPI: QSEECom_dealloc_memory 
03-12 10:11:16.722   767  4666 D QSEECOMAPI: QSEECom_shutdown_app, app_id = 478150660
03-12 10:11:16.723   767  4666 D         : CPPF_ServiceUninitialize: end! returns 0
03-12 10:11:16.723   767  4666 I WVCdm   : [cdm_engine.cpp(110):OpenSession] CdmEngine::OpenSession
03-12 10:11:16.724   767 22783 I WVCdm   : [(0):] Level3 Library 4445 Apr 20 2018 14:53:46
03-12 10:11:16.732   767  4666 I WVCdm   : [oemcrypto_adapter_dynamic.cpp(575):Initialize] L3 Initialized. Trying L1.
03-12 10:11:16.733   767  4666 D         : CPPF_ServiceInitialize: start!
03-12 10:11:16.733   767  4666 D QSEECOMAPI: QSEECom_get_handle sb_length = 0x2800
03-12 10:11:16.733   767  4666 D QSEECOMAPI: App is not loaded in QSEE
03-12 10:11:16.733   767  4666 D QSEECOMAPI: app_arch = 2, total_files = 9
03-12 10:11:16.738  9701 10261 W Conscrypt: Could not set socket write timeout: java.net.SocketException: Socket closed
03-12 10:11:16.738  9701 10261 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(Platform.java:132)
03-12 10:11:16.738  9701 10261 W Conscrypt:     at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.setSoWriteTimeout(ConscryptFileDescriptorSocket.java:926)
03-12 10:11:16.761  9701 10261 W Conscrypt: Could not set socket write timeout: java.net.SocketException: Socket closed
03-12 10:11:16.761  9701 10261 W Conscrypt:     at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(Platform.java:132)
03-12 10:11:16.761  9701 10261 W Conscrypt:     at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.setSoWriteTimeout(ConscryptFileDescriptorSocket.java:926)

To Use Google Drive API, you have to set OAuth 2.0 credentials using SHA-1 key. 要使用Google Drive API,您必须使用SHA-1密钥设置OAuth 2.0凭据。

reference: 参考:
https://developers.google.com/drive/android/auth https://developers.google.com/drive/android/auth

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM