2011-11-10 153 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(); 
        } 
        }     
      }