title: what can I do with this credentials gmail api oauth2 error?
body: <p>I'm trying to use oauth2 to access my email and interact with the account and a desktop api-receiving and sending emails-
  I used the example in java with gradle <a href="https://developers.google.com/gmail/api/quickstart/java" rel="nofollow noreferrer">https://developers.google.com/gmail/api/quickstart/java</a>
  and I get this error:</p>
  <blockquote>
  <p>Exception in thread &quot;main&quot; java.io.FileNotFoundException: Resource not found: C:/Users/xxx/Documents/tableaux dir/prjet email gmail/src/main/ressources/credential.json
  at GmailQuickstart.getCredentials(GmailQuickstart.java:50)
  at GmailQuickstart.main(GmailQuickstart.java:69)</p>
  </blockquote>
  <p>What can I do please ?</p>
  <p>The code</p>
  <pre><code>    import com.google.api.client.auth.oauth2.Credential;
  import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
  import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
  import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
  import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
  import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
  import com.google.api.client.http.javanet.NetHttpTransport;
  import com.google.api.client.json.JsonFactory;
  import com.google.api.client.json.gson.GsonFactory;
  import com.google.api.client.util.store.FileDataStoreFactory;
  import com.google.api.services.gmail.Gmail;
  import com.google.api.services.gmail.GmailScopes;
  import com.google.api.services.gmail.model.Label;
  import com.google.api.services.gmail.model.ListLabelsResponse;
  
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.security.GeneralSecurityException;
  import java.util.Collections;
  import java.util.List;
  
  /* class to demonstrate use of Gmail list labels API */
  public class GmailQuickstart {
      /** Application name. */
      private static final String APPLICATION_NAME = &quot;Gmail API Java Quickstart&quot;;
      /** Global instance of the JSON factory. */
      private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
      /** Directory to store authorization tokens for this application. */
      private static final String TOKENS_DIRECTORY_PATH = &quot;tokens&quot;;
  
      /**
       * Global instance of the scopes required by this quickstart.
       * If modifying these scopes, delete your previously saved tokens/ folder.
       */
      private static final List&lt;String&gt; SCOPES = Collections.singletonList(GmailScopes.GMAIL_LABELS);
      private static final String CREDENTIALS_FILE_PATH = &quot;C:/Users/xxx/Documents/tableaux dir/prjet email gmail/src/main/ressources/credential.json&quot;;
  
      /**
       * Creates an authorized Credential object.
       * @param HTTP_TRANSPORT The network HTTP Transport.
       * @return An authorized Credential object.
       * @throws IOException If the credentials.json file cannot be found.
       */
      private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
          // Load client secrets.
          InputStream in = GmailQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
          if (in == null) {
              throw new FileNotFoundException(&quot;Resource not found: &quot; + CREDENTIALS_FILE_PATH);
          }
          GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
  
          // Build flow and trigger user authorization request.
          GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                  HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                  .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                  .setAccessType(&quot;offline&quot;)
                  .build();
          LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
          Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize(&quot;user&quot;);
          //returns an authorized Credential object.
          return credential;
      }
  
      public static void main(String... args) throws IOException, GeneralSecurityException {
          // Build a new authorized API client service.
          final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
          Gmail service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
                  .setApplicationName(APPLICATION_NAME)
                  .build();
  
          // Print the labels in the user's account.
          String user = &quot;me&quot;;
          ListLabelsResponse listResponse = service.users().labels().list(user).execute();
          List&lt;Label&gt; labels = listResponse.getLabels();
          if (labels.isEmpty()) {
              System.out.println(&quot;No labels found.&quot;);
          } else {
              System.out.println(&quot;Labels:&quot;);
              for (Label label : labels) {
                  System.out.printf(&quot;- %s\n&quot;, label.getName());
              }
          }
      }
  }
  </code></pre>