java - Spreadsheet API - Retrieving a list of spreadsheets -
i want display spreadsheets of account ,
i build 2 spreadsheets on account , try code below ,
my spreadsheets have been setting public,
but got nothing ,
public class googlesheettest { private final static string[] scopes_array = {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"}; private final static string spreadsheet_url = "https://spreadsheets.google.com/feeds/spreadsheets/private/full"; private final static string spreadsheet_id = "xxxxxxxxxx@developer.gserviceaccount,com"; public static void main(string[] args) throws malformedurlexception, generalsecurityexception, ioexception, serviceexception { jacksonfactory json_factory = jacksonfactory.getdefaultinstance(); httptransport httptransport = googlenethttptransport.newtrustedtransport(); final list scopes = arrays.aslist(scopes_array); googlecredential credential = new googlecredential.builder() .settransport(httptransport) .setjsonfactory(json_factory) .setserviceaccountid(spreadsheet_id) .setserviceaccountprivatekeyfromp12file(new file("xxxxxxxx.p12")) .setserviceaccountscopes(scopes).build(); credential.refreshtoken(); spreadsheetservice service = new spreadsheetservice("spreadsheet_test"); service.setoauth2credentials(credential); url spreadsheet_feed_url = new url(spreadsheet_url); spreadsheetfeed feed = service.getfeed(spreadsheet_feed_url,spreadsheetfeed.class); list<spreadsheetentry> spreadsheets = feed.getentries(); (spreadsheetentry spreadsheet:spreadsheets){ system.out.println(spreadsheet.gettitle().getplaintext()); } }
i grateful can provide.
Comments
Post a Comment