使用 Java 客户端向使用 gdata 的 Google 文档列表 API 发出发布请求。

发布于 2024-09-15 22:24:41 字数 432 浏览 4 评论 0原文

我想复制此处提到的文档:

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

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

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

奖励点如果将其包装到一个采用两个字符串的方法中,一个是源名称,另一个是副本名称。

I want to copy a document as mentioned here:

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

I am using the latest Java Gdata Library, which doesn't have a nice wrapper method to do it, and I am a newb to the java gdata lib.

I have already got an authenticated DocsService, if that is useful.

Bonus points if you wrap it un into a method which takes two Strings, one being the source name and the other being the copy name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

农村范ル 2024-09-22 22:24:41

好吧,我做到了...

只是为了让每个人都可以看到... 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");
        }

}

Ok I did it....

Just so everyone can see... this.dService is a DocsService, that already has been authenticated.

// 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");
        }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文