Android - Google Spreadsheet Api

23,320

Solution 1

At the end the libraries i used are:

gdata-client-1.0.jar
gdata-client-meta-1.0.jar
gdata-core-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.12.0-beta.jar
google-api-client-android-1.12.0-beta.jar
google-http-client-1.12.0-beta.jar
google-http-client-android-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
gson-2.1.jar
guava-13.0.1.jar
jackson-core-asl-1.9.9.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar

As suggested by Eugenio (thanks for that!!!) i "mixed" libraries from spreadsheet api with the java-client-api and after the authentication i used the following for getting the cells

SpreadsheetEntry spreadsheet = null;
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");

SpreadsheetFeed spreadsheetFeed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = spreadsheetFeed.getEntries();
for (SpreadsheetEntry entry : spreadsheets) {
   if (entry.getTitle().getPlainText().equals(spreadsheetTitle)) {
      spreadsheet = entry;
   }
}

if (spreadsheet == null) {
    throw new FileNotFoundException("Cannot find the required spreadsheet '" + spreadsheetTitle + "'");
}

WorksheetEntry worksheet = null;
WorksheetFeed worksheetFeed = service.getFeed(spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
    for (WorksheetEntry entry : worksheets) {
    if (entry.getTitle().getPlainText().equals(worksheetTitle)) {
         worksheet = entry;
    }
}

if (worksheet == null) {
    throw new FileNotFoundException("Cannot find the required worksheet '" + worksheetTitle + "'");
}

URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);

For the moment i used the "worst" authentication system and i should turn this in the OAuth2 but for the moment the ClientLogin is done in this way:

SpreadsheetService service = new SpreadsheetService("v1");
service.setProtocolVersion(SpreadsheetService.Versions.V3);
service.setUserCredentials(email, password);

Solution 2

Short answer: All three

Long answer:

You will have to use the new Drive API, which allows to upload, download and modify files in Google Drive. With this you only have limited operations on spreadsheets, basically download it or upload it.

The Google Spreadsheet Api allows to make complex operations in spreadsheets, like accessing data by row and column.

The Google API java client is a dependency in all Google APIs, it is used to authorize the connection in different ways, such as OAuth or service accounts.

Share:
23,320
Lorenzo Sciuto
Author by

Lorenzo Sciuto

Software Engineer with 10+ years experience in R&amp;D for IT and Robotics solutions.

Updated on July 09, 2022

Comments

  • Lorenzo Sciuto
    Lorenzo Sciuto almost 2 years

    I can't get which libs i should use for developing an Android app that menages Google spreadsheet. I need connecting, copying, editing, reading from a user spreadsheet but i can't understand today which is the way.

    Google Drive Api : https://developers.google.com/drive/
    Google Spreadsheet Api: https://developers.google.com/google-apps/spreadsheets/
    Google APi java client: http://code.google.com/p/google-api-java-client/
    

    Which is the correct one?

  • Lorenzo Sciuto
    Lorenzo Sciuto over 11 years
    Thanks for your reply! ..do you have any tutorial or a downloadable example? i cannot understand how to integrate them together..
  • Eugenio Cuevas
    Eugenio Cuevas over 11 years
    Well, not with all three together, but this tutorial uses client API and Drive API, using Spreadsheet API should be straightforward after that
  • Lorenzo Sciuto
    Lorenzo Sciuto over 11 years
    i actually never worked on it again.. i used ontly the described authentication. Sorry..
  • rahulserver
    rahulserver almost 10 years
    @EugenioCuevas The link is dead.
  • Ofek Agmon
    Ofek Agmon over 9 years
    is there an example of doing the OAuth 2.0 in android? it has do be done before accessing the sheets API right?
  • Fasiha
    Fasiha over 8 years
    but it will return all the spreadsheets, how cloud i try to access specific spread sheet
  • Lorenzo Sciuto
    Lorenzo Sciuto over 8 years
    @Fasiha it actually selects one specific speadsheet...and one specific worksheet inside it too... give a try to the code...