Search code examples
javagoogle-data-api

Manipulating single cell in a google spreadsheet


So for an application that I am writing for a friend of mine, I needed to interact with the google drive and google data api in order to create folders and manipulate data in a google spreadsheet.

Now looking at the API beforehand it all seemed pretty straightforward. Until you actually make a start and figure out that every piece of documentation you could possibly find on the internet is pretty much deprecated.

Eventually I figured out most parts after some time on the internet (Like authentication and creating new folders / copying files etc.) so far so good.

But now I have come at the following problem: I am trying to manipulate a single cell (Well actually multiple but 1 by 1) and after 2 days of going through google's atrocious documentation I have turned to you guys.

I have come as far as authenticating my user and even reading the values from the spreadsheet however I can't seem to write to it.

CellEntry newEntry = new CellEntry(row,col, "value");
service.insert(cellFeedUrl, newEntry);
System.out.println("Added!");

This is what I got from their code sample, however the service.insert() returns an error

 Exception in thread "main" com.google.gdata.util.ServiceException: Internal Server Error
Internal Error

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:632)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.insert(Service.java:1409)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:613)

I really hope someone here can help me out, I am pretty desperate and google has not been my friend on this one (Neither has google's own documentation)

  • A.E.

Solution

  • I figured it out myself,

    As I already said in one of the comments I passed a value of 0 to variable col, passing that to the google server gave me an error back.

    Changing the loop that was calling:

     new CellEntry(row,col, "value");
    

    To start at 1 instead of 0 fixed it.

    • AE