title: Is there some way to include multiple Google API services (e.g. Sheets and Docs) for a single Java project?
body: <p>I'm using Google's API services for the first time for a personal Java project involving reading data from a Google Sheet and writing information relating to it to a separate Google Doc.</p>
  <p>I've used Google's Quickstart Guides for both listed <a href="https://developers.google.com/sheets/api/reference/rest" rel="nofollow noreferrer">here</a> and <a href="https://developers.google.com/docs/api/quickstart/java" rel="nofollow noreferrer">here</a>. I managed to get everything up and running just fine when following the Google Sheets guide and have tested it with my own file as well.</p>
  <p>However, attempting to set up the API for the Doc seems to give issues when trying to add in my newly generated credentials (Google Doc) to the already created credentials.json file. I assume that this is due to the fact that the credentials were already created for my Sheets file, and so I cannot simply add in the newly created credentials. I also attempted doing this by creating a new credentials file named doccredentials.json to attempt to use both, but am met with this when attempting to perform <code>gradle run</code> again in order to compile the Google Doc API services:</p>
  <pre><code>Exception in thread &quot;main&quot; com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
  {
    &quot;code&quot; : 403,
    &quot;errors&quot; : [ {
      &quot;domain&quot; : &quot;global&quot;,
      &quot;message&quot; : &quot;Insufficient Permission&quot;,
      &quot;reason&quot; : &quot;insufficientPermissions&quot;
    } ],
    &quot;message&quot; : &quot;Request had insufficient authentication scopes.&quot;,
    &quot;status&quot; : &quot;PERMISSION_DENIED&quot;
  }
  </code></pre>
  <p>My best guess is that the credentials for the Sheet are being used, but I'm not sure how to circumvent that. I've also ensured that my <code>CREDENTIALS_FILE_PATH</code> variable is set to the right location too so I'm pretty sure that it is attempting to read from the right file.</p>
  <p>Any suggestions would be appreciated. Thanks.</p>
  <p>EDIT: Here is what I have in my authentication block of code. It was originally set up just to authenticate the Sheet API, however, after double checking it seems it may most likely be due to setting the Scopes incorrectly. Any suggestions on how to allow the scope to be for both Spreadsheets and Docs?:</p>
  <pre><code>private static Credential authorize() throws IOException, GeneralSecurityException {
      InputStream in = InventoryManagerSheet.class.getResourceAsStream(&quot;/credentials.json&quot;);
      GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(in));
  
      List&lt;String&gt; scopes = Arrays.asList(SheetsScopes.SPREADSHEETS);
  
      GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(),
      clientSecrets, scopes).setDataStoreFactory(new FileDataStoreFactory(new java.io.File(&quot;tokens&quot;))).setAccessType(&quot;offline&quot;).build();
  
      Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(&quot;user&quot;);
  
      return credential;
  }
  </code></pre>