GoogleApiClient.addApi() doesn't support Gmail

2019-07-01 15:17发布

问题:

I'm trying to use the following code to get an authentication with the given APIs but the addApi is neither recognizing Gmail as an API or Gmail.API as an API. Because of this I'm getting an Unauthorized 401 going further into the application when trying to retrieve the messages.

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .addApi(Gmail)
                .addScope(GmailScopes.GMAIL_READONLY)
                .build();