google-services icon indicating copy to clipboard operation
google-services copied to clipboard

Calendar.calendarList().list().execute() throws java.lang.IllegalArgumentException

Open DimovskiD opened this issue 4 years ago • 0 comments

  • Device: any
  • OS version: any
  • SDK version: any
  • [Android] Google Play Services version: 19.2.0

Calendar.calendarList().list().execute() throws 'java.lang.IllegalArgumentException: the name must not be empty: null' even though the credential.selectedAccountName is set. The problem occurs as an edge case and is related to #410

Steps to reproduce:

  1. Login with Google account to application & fetch calendars (works fine)
  2. Remove Google account from Android OS
  3. GoogleSignIn.getLastSignedInAccount() will return the account as logged in, although it has been removed from the device
  4. Using this account's username as a value for credential.selectedAccountName results in 'java.lang.IllegalArgumentException: the name must not be empty: null'

Expected Results: Either GoogleSignIn.getLastSignedAccount() should not return the account that has been removed, or the calendar API should be able to use this account as a credential, since it is "logged in"

Relevant Code:

    private val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail().requestScopes(Scope("https://www.googleapis.com/auth/calendar"))
        .build()
    private val  mGoogleSignInClient = GoogleSignIn.getClient(context, gso)
    private val account = GoogleSignIn.getLastSignedInAccount(activity)
    account?.let {
         val credential = GoogleAccountCredential.usingOAuth2(context, Collections.singleton(
            CalendarScopes.CALENDAR)); //Google credential for authentication
        credential.selectedAccountName = it.email
        client = Calendar.Builder(
            AndroidHttp.newCompatibleTransport(), GsonFactory.getDefaultInstance(), credential
        ).setApplicationName("AppName").build()    
        val list = client.calendarList().list().execute().items  //this line throws java.lang.IllegalArgumentException: the name must not be empty: null
    }

DimovskiD avatar Dec 09 '21 15:12 DimovskiD