How do I connect Android apps with Google Sheets spreadsheets?

后端 未结 4 817
难免孤独
难免孤独 2020-12-14 12:08

I\'m trying to do an Android app that needs to work with Google spreadsheet API. I\'m new in this, so I\'m starting with the version 3 of the api: https://developers.google.

4条回答
  •  攒了一身酷
    2020-12-14 13:05

    Thank you so so much Scorpion! It works!! I've been trying this for too long. Ok here is my solution: I started a new project and included these jars:

    gdata-client-1.0
    gdata-client-meta-1.0
    gdata-core-1.0
    gdata-spreadsheet-3.0
    gdata-spreadsheet-meta-3.0
    guava-13.0.1  
    

    and my code:

        SpreadsheetService spreadsheet= new SpreadsheetService("v1");
        spreadsheet.setProtocolVersion(SpreadsheetService.Versions.V3);
    
        try {
            spreadsheet.setUserCredentials("username", "password");
            URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
            SpreadsheetFeed feed = spreadsheet.getFeed(metafeedUrl, SpreadsheetFeed.class);
    
            List spreadsheets = feed.getEntries();
            for (SpreadsheetEntry service : spreadsheets) {             
                System.out.println(service.getTitle().getPlainText());
           }
        } catch (AuthenticationException e) {           
            e.printStackTrace();
        }
    

    of course this is executed in a different thread not in the main thread. There is no java documentation for OAuth 2.0 but I will try and if I can't do it I'll ask here. Again, thank you very much and I hope to help you when I work on this time enough. :)

提交回复
热议问题