0

我正在尝试使用 Java 以编程方式将页面添加到我的 Google 站点。这是代码:

    import java.io.*;
    import java.net.MalformedURLException;
    import java.net.URL;

import com.google.gdata.client.sites.*;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.XhtmlTextConstruct;
import com.google.gdata.data.sites.*;
import com.google.gdata.util.ServiceException;
import com.google.gdata.util.XmlBlob;


public class PageCreate {
public static void main(String args[]) throws Exception {
    WebPageEntry createdEntry = createWebPage("New Webpage Title", "<b>HTML content</b>");
    System.out.println("Created! View at " + createdEntry.getHtmlLink().getHref());
}
private static void setContentBlob(BaseContentEntry<?> entry, String pageContent) {
      XmlBlob xml = new XmlBlob();
      xml.setBlob(pageContent);
      entry.setContent(new XhtmlTextConstruct());
    }

    public static WebPageEntry createWebPage(String title, String content)
        throws ServiceException, IOException, MalformedURLException {
      SitesService client = new SitesService("*****-pagecreate-v1");
      client.setUserCredentials("***********", "*********");

      client.site = "intratrial2"; -> ***SYNTAX ERROR REPORTED***

      //ContentFeed contentFeed = client.getFeed(new URL(buildContentFeedUrl()), ContentFeed.class);
      WebPageEntry entry = new WebPageEntry();
      entry.setTitle(new PlainTextConstruct(title));

      setContentBlob(entry, content); // Entry's HTML content

      return client.insert(new URL(buildContentFeedUrl()), entry);
    }


      public static String buildContentFeedUrl() {
          String domain = "*****";  // OR if the Site is hosted on Google Apps, your domain (e.g. example.com)
          String siteName = "intratrial2";
          return "https://sites.google.com/feeds/content/" + domain + "/" + siteName + "/";
        }
}

如果我用语法错误注释掉该行,我会在运行时收到以下错误报告:线程“主”com.google.gdata.util.ServiceException 中的异常:内部服务器错误内部错误

我不确定我在这里做错了什么,我非常感谢一些帮助。谢谢。

4

0 回答 0