2 thoughts on “Write data to google spreadsheet using service account and oauth authentication”

  1. Thank you, after a lot of efforts I am able to run the code and get the results,
    but it is adding new row each time the code excutes, how to just update the same row everytime.

    1. FYI, i tried this code to update a single row.
      URL listFeedUrl = worksheet.getListFeedUrl();
      ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

      // TODO: Choose a row more intelligently based on your app’s needs.
      ListEntry row = listFeed.getEntries().get(0);

      // Update the row’s data.
      row.getCustomElements().setValueLocal(“firstname”, “Sarah”);
      row.getCustomElements().setValueLocal(“lastname”, “Hunt”);
      row.getCustomElements().setValueLocal(“age”, “32”);
      row.getCustomElements().setValueLocal(“height”, “154”);

      // Save the row using the API.

      but i get this error in eclipse
      Exception in thread “main” java.lang.ClassCastException: com.google.gdata.data.TextContent cannot be cast to com.google.gdata.data.OutOfLineContent
      at com.google.gdata.data.spreadsheet.WorksheetEntry.getFeedUrlString(WorksheetEntry.java:129)
      at com.google.gdata.data.spreadsheet.WorksheetEntry.getListFeedUrl(WorksheetEntry.java:98)

      Any solution for this?

Leave a Reply

Your email address will not be published. Required fields are marked *