title: com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
body: <p>I want to use Java Google Drive API.
  I tried this code:</p>
  
  <pre><code>public Drive getDriveService() throws GeneralSecurityException, IOException, URISyntaxException
      {
          HttpTransport httpTransport = new NetHttpTransport();
          JacksonFactory JSON_FACTORY = new JacksonFactory();
  
          GoogleCredential credential = new GoogleCredential.Builder()
              .setTransport(httpTransport)
              .setJsonFactory(JSON_FACTORY)
              .setServiceAccountId("sonoratestw-226@sonora-project.iam.gserviceaccount.com")
              .setServiceAccountPrivateKeyFromP12File(new java.io.File("C:\\buffer\\sonora project-3256770463ed.p12"))
              .setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
              .setServiceAccountUser("sonoratestw@gmail.com")
              .build();
  
          Drive service = new Drive.Builder(httpTransport, JSON_FACTORY, null)
              .setApplicationName("FileListAccessProject")
              .setHttpRequestInitializer(credential).build();
  
          return service;
      }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>An error occurred: com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
  </code></pre>
  
  <p>I use this configuration:</p>
  
  <p><a href="https://i.stack.imgur.com/GtWCQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GtWCQ.png" alt="enter image description here"></a></p>
  
  <p>Can you give some idea how I can fix this?</p>