【问题标题】:Issue in reading google text document阅读谷歌文本文档时的问题
【发布时间】:2012-06-23 07:31:30
【问题描述】:

我可以获得我需要的 google 文本文档的句柄。我现在被困在如何阅读内容上。 我的代码如下:

            GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();  
            oauthParameters.setOAuthConsumerKey(Constants.CONSUMER_KEY);  
            oauthParameters.setOAuthConsumerSecret(Constants.CONSUMER_SECRET);  
            oauthParameters.setOAuthToken(Constants.ACCESS_TOKEN); 
            oauthParameters.setOAuthTokenSecret(Constants.ACCESS_TOKEN_SECRET);  
            DocsService client = new DocsService("sakshum-YourAppName-v1");  
            client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());  
            URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full/");  
            DocumentQuery dquery = new DocumentQuery(feedUrl);
            dquery.setTitleQuery("blood_donor_verification_template_dev");
            dquery.setTitleExact(true);
            dquery.setMaxResults(10);
            DocumentListFeed resultFeed = client.getFeed(dquery, DocumentListFeed.class);
            System.out.println("feed size:" + resultFeed.getEntries().size());
            String emailBody = "";
            for (DocumentListEntry entry : resultFeed.getEntries()) {  

                System.out.println(entry.getPlainTextContent()); 
                emailBody = entry.getPlainTextContent();
            }  

请注意 entry.getPlainTextContent() 不起作用并抛出 object not TextContent 类型异常

【问题讨论】:

  • 这方面有什么帮助吗?

标签: gdata-api


【解决方案1】:

最后我解决了:

for (DocumentListEntry entry : resultFeed.getEntries()) {  
                String docId = entry.getDocId();
                String docType = entry.getType();
                URL exportUrl =
                              new URL("https://docs.google.com/feeds/download/" + docType
                                  + "s/Export?docID=" + docId + "&exportFormat=html");
                MediaContent mc = new MediaContent();
                mc.setUri(exportUrl.toString());

                MediaSource ms = client.getMedia(mc);
                InputStream inStream = null;
                try {
                    inStream = ms.getInputStream();
                    int c;
                    while ((c = inStream.read()) != -1) {
                        emailBody.append((char)c);
                    }
                  } finally {
                    if (inStream != null) {
                      inStream.close();
                    }
                  }                 
            }

【讨论】:

    猜你喜欢
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多