电子表格API - 检索电子表格列表

时间:2015-08-25 01:51:33

标签: java google-api google-sheets

我想显示我帐户的所有电子表格,

我在我的帐户上构建了2个电子表格,并尝试使用以下代码,

我的电子表格一直在公开,

但总是一无所获,

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();
        for (SpreadsheetEntry spreadsheet:spreadsheets){
        System.out.println(spreadsheet.getTitle().getPlainText());
    }
}

我将非常感谢您提供的任何帮助。

0 个答案:

没有答案