Before accessing the credentials object, one needs to create application default credentials, as described in the "Google Application Default Credentials" documentation
page. A step-by-step procedure is given there at sub-chapter "How the Application Default Credentials work". One needs to set up default credentials using the developers' console.