繁体   English   中英

Java ::使用最新的Google Sheets v4 API以编程方式创建电子表格

[英]Java :: Creating a spreadsheet programmatically using latest Google Sheets v4 API

我有一个用例,需要提取新创建的Google Spreadsheet的Spreadsheet ID。 我引用了Google文档,发现Google Sheets API v4中的Spreadsheet.create方法返回了Spreadsheet ID作为响应。

但是,我无法获得如何在Java中使用此方法。

另外,通过引用Google文档( Link ),我还知道我也需要OAuth授权。 请帮助我了解如何使用Java设置OAuth授权,或者如果存在使用Java与OAuth创建Google电子表格的示例,请分享。

请遵循Sheets API文档中的Java快速入门 授权部分包含在快速入门中。

这是Java凭证部分的代码段:

public static Credential authorize() throws IOException {
        // Load client secrets.
        InputStream in =
            Quickstart.class.getResourceAsStream("/client_secret.json");
        GoogleClientSecrets clientSecrets =
            GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow.Builder(
                        HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(DATA_STORE_FACTORY)
                .setAccessType("offline")
                .build();
        Credential credential = new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize("user");
        System.out.println(
                "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
        return credential;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM