Отправьте запрос с помощью клиента Java в API Списка документов Google с помощью gdata. - PullRequest
2 голосов
/ 24 августа 2010

Я хочу скопировать документ, как упомянуто здесь:

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

Я использую новейшую библиотеку Java Gdata, в которой нет подходящего метода-оболочки для этого,и я новичок в java gdata lib.

Я уже получил аутентифицированный DocsService, если это полезно.

Бонусные баллы если вы включите его в метод, который принимает две строки, одна из которых является именем источника, а другая - именем копии.

1 Ответ

1 голос
/ 24 августа 2010

Хорошо, я сделал это ....

Точно так же все могут видеть ... 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");
        }

}
...