title: when i try to list gmail threads using Gmail API i get GoogleJsonResponseException: 500 Internal Server Error
body: <p>I am trying to use GMAIL API to download attachments from my email account using OAuth 2.0 server to server Application. Here is my code:</p>
  
  <pre><code>    private static final String USER = "MYACCOUNT@gmail.com";
      private static String emailAddress = "XXXXXXXX@developer.gserviceaccount.com";
      {
         try {
                httpTransport = GoogleNetHttpTransport.newTrustedTransport();
                credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)
                .setJsonFactory(JSON_FACTORY)
                .setServiceAccountId(emailAddress)
                .setServiceAccountPrivateKeyFromP12File(new File("myfile.p12"))
                .setServiceAccountScopes(Collections.singleton(GmailScopes.GMAIL_READONLY))
                .build();
            }
            catch (IOException | GeneralSecurityException e)
            {
                throw new RuntimeException(e);
            }
      }
      // Create a new authorized Gmail API client
      Gmail service = new Gmail.Builder(httpTransport, JSON_FACTORY, credential)
          .setApplicationName(APP_NAME).build();
  
      // Retrieve a page of Threads
      ListThreadsResponse threadsResponse = service.users().threads().list(USER).execute();
        List&lt;Thread&gt; threads = threadsResponse.getThreads();
  
     // Print ID of each Thread.
      for (Thread thread : threads) {
        System.out.println("Thread ID: " + thread.getId());
  
  }
  </code></pre>
  
  <p>I get the error at the threadsResponse call. These are the errors:</p>
  
  <p>Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error.</p>
  
  <p>{
    "code" : 500,
    "errors" : [ {
      "domain" : "global",
      "message" : "Backend Error",
      "reason" : "backendError"
    } ],
    "message" : "Backend Error"
  }
      at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1049)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
      at core.crescent.gmail.GmailApiQuickstart.main(GmailApiQuickstart.java:192)</p>