How to get data directly from google spreadsheet?

I need an android app to connect ALWAYS to the same google spreadsheet to get cell data (which I will change every day in the future so the app can get updated data without using a server).

In the documentation https://developers.google.com/google-apps/spreadsheets/?hl=it#ListFeeds it showed how to authenticate, etc., but I needed to connect to an open spreadsheet using a direct link like

https://docs.google.com/spreadsheet/ccc?key=xxx ....

Is it possible?

+3


source to share


1 answer


Perhaps James Moore's code can be used as an example http://blog.restphone.com/2011/05/very-simple-google-spreadsheet-code.html

Remember, you need to add manually to the File-> Publish to Internet table



package com.banshee;

    import java.io.IOException;
    import java.net.URL;

    import com.google.gdata.client.spreadsheet.SpreadsheetService;
    import com.google.gdata.data.spreadsheet.CustomElementCollection;
    import com.google.gdata.data.spreadsheet.ListEntry;
    import com.google.gdata.data.spreadsheet.ListFeed;
    import com.google.gdata.util.ServiceException;

    public class SpreadsheetSucker {
      public static void main(String[] args) {
        SpreadsheetService service = new SpreadsheetService("com.banshee");
        try {
          // Notice that the url ends
          // with default/public/values.
          // That wasn't obvious (at least to me)
          // from the documentation.
          String urlString = "https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";

          // turn the string into a URL
          URL url = new URL(urlString);

          // You could substitute a cell feed here in place of
          // the list feed
          ListFeed feed = service.getFeed(url, ListFeed.class);

          for (ListEntry entry : feed.getEntries()) {
            CustomElementCollection elements = entry.getCustomElements();
            String name = elements.getValue("name");
            System.out.println(name);
            String number = elements.getValue("Number");
            System.out.println(number);
          }
        } catch (IOException e) {
          e.printStackTrace();
        } catch (ServiceException e) {
          e.printStackTrace();
        }

      }
    }

      

+3


source







All Articles