【问题标题】:Make a Post Request using Java client to the Google Documents List API using gdata.使用 Java 客户端向使用 gdata 的 Google 文档列表 API 发出发布请求。
【发布时间】:2011-04-03 03:13:10
【问题描述】:

我想复制这里提到的文件:

http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#CopyingDocs

我正在使用最新的 Java Gdata 库,它没有很好的包装方法,而且我是 java gdata 库的新手。

如果有用的话,我已经获得了经过身份验证的 DocsService。

加分如果你将它包装成一个需要两个字符串的方法,一个是源名称,另一个是副本名称。

【问题讨论】:

    标签: java gdata-api gdata


    【解决方案1】:

    好吧,我做到了……

    让每个人都可以看到... this.dService 是一个 DocsService,已经过身份验证。

    // This method returns the Resource ID to be used to make the copy
    public String loadDocsSpreadsheetEntryId(String sourceName) {
        String resourceId = null;
        try {
    
        Logger.info("Loading feed URL");
        URL url = new URL("https://docs.google.com/feeds/default/private/full" );
        DocumentQuery query = new DocumentQuery(url);
        query.setTitleQuery(sourceName);
        query.setTitleExact(true);
    
        Logger.info("Loaded feed URL");
        DocumentListFeed dfeed = this.dService.getFeed(query, DocumentListFeed.class);
        Logger.info("got feed");
        for (DocumentListEntry entry : dfeed.getEntries()) {
            Logger.info(entry.getTitle().getPlainText());
            if(entry.getTitle().getPlainText().equalsIgnoreCase(sourceName))
            {
                Logger.info("found doc");
                resourceId = entry.getResourceId();
            }
         }
        } catch(Exception e) {
            logException(e, "Loading Source Spreadsheet to copy");
        }
    
        return resourceId;
    }
    
        public void createSpreadsheetFrom(String destination, String source) {
            try {
            URL entryUrl = new URL("http://docs.google.com/feeds/default/private/full");
            Map<String, String> parameters = new HashMap<String, String>();
            String resourceID = loadDocsSpreadsheetEntryId(source);
            Logger.info("Resource id %s", resourceID);
    
            DocumentListEntry newEntry = new DocumentListEntry();
            newEntry.setId(resourceID);
            newEntry.setTitle(new PlainTextConstruct(destination));
            this.dService.insert(entryUrl, newEntry);
    
            } catch(Exception e) {
                logException(e, "Copying Spreadsheet");
            }
    
    }
    

    【讨论】:

    • 感谢马克发布您的解决方案,这正是我正在寻找的东西,我处于同样的情况需要复制电子表格。很有帮助!
    猜你喜欢
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2020-12-09
    • 2015-10-15
    • 2022-01-12
    • 2020-10-10
    • 2022-10-16
    • 2016-07-02
    相关资源
    最近更新 更多