title: AuthenticationException error while adding data to Google Sheet using Java
body: <p>I am trying to add data to Google Sheet using Java. To do this I am following this <a href="https://templth.wordpress.com/2014/11/19/interacting-with-google-spreadsheet-with-java/" rel="nofollow noreferrer">article</a>.
  Here is my code</p>
  <pre><code>@SpringBootApplication
  public class SheetService {
      SpreadsheetService service = new SpreadsheetService(&quot;spreadsheetservice&quot;);
  
      public String setUserCredentials(String username, String password) {
          try {
              service.setUserCredentials(username, password);
              return &quot;Credentials set.&quot;;
          } catch (AuthenticationException authenticationException) {
              authenticationException.printStackTrace();
              return &quot;Error&quot;;
          }
      }
  
      private static final String SPREADSHEET_SERVICE_URL  = &quot;https://spreadsheets.google.com/feeds/spreadsheets/private/full&quot;;
  
  
      public SpreadsheetEntry getSpreadsheet(String sheetName) {
          try {
              URL spreadSheetFeedUrl = new URL(SPREADSHEET_SERVICE_URL);
  
              SpreadsheetQuery spreadsheetQuery = new SpreadsheetQuery(
                      spreadSheetFeedUrl);
              spreadsheetQuery.setTitleQuery(sheetName);
              spreadsheetQuery.setTitleExact(true);
              SpreadsheetFeed spreadsheet = service.getFeed(spreadsheetQuery,
                      SpreadsheetFeed.class);
  
              if (spreadsheet.getEntries() != null
                      &amp;&amp; spreadsheet.getEntries().size() == 1) {
                  return spreadsheet.getEntries().get(0);
              } else {
                  return null;
              }
          } catch (Exception ex) {
              System.out.println(&quot;Exception&quot;);
          }
  
          return null;
      }
  
      public WorksheetEntry getWorkSheet(String sheetName, String workSheetName) {
          try {
              SpreadsheetEntry spreadsheet = getSpreadsheet(sheetName);
  
              if (spreadsheet != null) {
                  WorksheetFeed worksheetFeed = service.getFeed(
                          spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
                  List&lt;WorksheetEntry&gt; worksheets = worksheetFeed.getEntries();
  
                  for (WorksheetEntry worksheetEntry : worksheets) {
                      String wktName = worksheetEntry.getTitle().getPlainText();
                      if (wktName.equals(workSheetName)) {
                          return worksheetEntry;
                      }
                  }
              }
          } catch (Exception ex) {
              System.out.println(&quot;Exception&quot;);
          }
  
          return null;
      }
  
      public ListEntry createRow(Map&lt;String, String&gt; rowValues) {
          ListEntry row = new ListEntry();
          for (String columnName : rowValues.keySet()) {
              String value = rowValues.get(columnName);
              row.getCustomElements().setValueLocal(columnName, value);
          }
          return row;
      }
  
      String username = &quot;******@gmail.com&quot;;
      String password = &quot;*******&quot;;
      String sheetName = &quot;*******&quot;;
      String workSheetName = &quot;Sheet1&quot;;
      String res = setUserCredentials(username, password);
      WorksheetEntry worksheet = getWorkSheet(sheetName, workSheetName);
      URL listFeedUrl = worksheet.getListFeedUrl();
      Map&lt;String,String&gt; rowValues = new HashMap&lt;&gt;();
      public SheetService() throws IOException, ServiceException {
          rowValues.put(&quot;name&quot;, &quot;Nikhil&quot;);
      }
  
  
      ListEntry row = createRow(rowValues);
      ListEntry addedRow = service.insert(listFeedUrl, row);
  
      public static void main(String[] args) {
          SpringApplication.run(SheetService.class, args);
      }
  }
  
  
  </code></pre>
  <p>While I try to run this, I keep getting the error <code>com.google.gdata.util.AuthenticationException: Error authenticating (check service name)</code>.</p>
  <p>Can anyone please help.
  Also if someone knows another easier way to populate data into a Google sheet, I'll be grateful to know that. Any help will be highly appreciated.</p>