If you take a look at the documentation, you can specify the client_secret, and client_id parameters instead of using the client_secrets file.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID,CLIENT_SECRET,
Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)).setDataStoreFactory(
DATA_STORE_FACTORY).build();
Using this method worked for me.