title: When Service Account creates Google Sheets,The permission is needed. How can I give a permission?
body: <p>I am using Google Sheet API (V4). </p>
  
  <p>I had my google account like "test@google.com". To use google api, I made a project in Google Console and created service account. </p>
  
  <p>I want to create a Google Sheet that can be accessed by only authorized person and myself who create the sheet. The authorized person can read and edit. Either do i. </p>
  
  <p>But whenever I tired my code, it went well and I can get the sheet url. but when I click the url they show I need a permission.
   It is the url that I created [<a href="https://docs.google.com/spreadsheets/d/1RKR-ErUaC_LujUUDf8o_yIprEz223U1EltJ7zYPo7us/edit]" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1RKR-ErUaC_LujUUDf8o_yIprEz223U1EltJ7zYPo7us/edit]</a></p>
  
  <p>I think the problem is I am using a service account for OAuth. I need to use this. </p>
  
  <p>So.. I want to create google sheet and give a permission to read and edit to person I select. </p>
  
  <p>Please help me out...!</p>
  
  <pre><code> /**
   * Application name.
   */
  private static final String APPLICATION_NAME = "Google Sheets API Java";
  
  /**
   * Global instance of the JSON factory.
   */
  private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
  /**
   * Global instance of the HTTP transport.
   */
  private static HttpTransport HTTP_TRANSPORT;
  
  /**
   * Global instance of the scopes required by this quickstart.
   * &lt;p&gt;
   * If modifying these scopes, delete your previously saved credentials
   * at ~/.credentials/sheets.googleapis.com-java-quickstart
   */
  private static final List&lt;String&gt; SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);
  
  static {
      try {
          HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
      } catch (Throwable t) {
          t.printStackTrace();
          System.exit(1);
      }
  }
  
  /**
   * Creates an authorized Credential object.
   *
   * @return an authorized Credential object.
   * @throws IOException
   */
  public Credential authorize() throws IOException {
      // Load client secrets.
      InputStream in = GoogleSheetConfig.class.getResourceAsStream("/My Service Account Information.json");
      GoogleCredential credential = GoogleCredential
              .fromStream(in)
              .createScoped(SCOPES);
      return credential;
  }
  
  /**
   * Build and return an authorized Sheets API client service.
   *
   * @return an authorized Sheets API client service
   * @throws IOException
   */
  @Bean
  public Sheets getSheetsService() throws Exception {
      Credential credential = authorize();
      return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
              .setApplicationName(APPLICATION_NAME)
              .build();
  }
  </code></pre>
  
  <p>my Service Account Information is like :</p>
  
  <pre><code>{
  "type": "service_account",
  "project_id": "my project id ",
  "private_key_id": "fb925c0954********",
  "private_key": 
  "client_email": "test-service-accoun@admin-auth-
  test.iam.gserviceaccount.com",
  "client_id": "my client id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": 
  "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": 
  "https://www.googleapis.com/robot/v1/metadata/x509/admin-auth-test-
  service-accoun%40admin-auth-test.iam.gserviceaccount.com"
  }
  </code></pre>
  
  <p>Below is my test code to create the sheet :</p>
  
  <pre><code>Spreadsheet requestBody = new Spreadsheet();
  
  Sheets.Spreadsheets.Create request = sheets.spreadsheets().create(requestBody);
  
  Spreadsheet response = request.execute();
  System.out.println(response);
  </code></pre>