2011-11-10 116 views
0

问题我可以得到我需要的谷歌文本文档的句柄。我现在被困在如何阅读内容。 我的代码如下所示:阅读谷歌文本文档

  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(); 
      } 

PLZ注意entry.getPlainTextContent()不工作,并抛出对象没有的TextContent类型的异常

+0

任何帮助的这个好吗? – Vik

回答

0

我终于解决了这个问题为:

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(); 
        } 
        }     
      }