使用Google API将网站添加到Google网站管理员

时间:2013-10-10 02:31:56

标签: java api google-api google-webmaster-tools

我正在尝试通过编写一个小型java程序来简化我的生活,该程序会将网站添加到网站管理员帐户并验证它们。

我在他们的api文档中使用了google的示例代码:

public static SitesEntry insertSite(WebmasterToolsService myService, 
    String siteUrl) throws IOException, ServiceException {
  SitesEntry entry = new SitesEntry();
  OutOfLineContent content = new OutOfLineContent();
  content.setUri(siteUrl);
  entry.setContent(content);
  System.out.println("Site: " + siteUrl + " now being added.");
  return myService.insert(getSitesFeedUrl(), entry);
}

然而,我一直在:

Site: www.mydomain.com now being added.
com.google.gdata.util.InvalidEntryException: Bad Request
[Line 1, Column 406, element atom:content] No xml:base established--need an absolute URI.: www.mydomain.com
    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:602)
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
    at com.google.gdata.client.Service.insert(Service.java:1409)
    at com.google.gdata.client.GoogleService.insert(GoogleService.java:613)
    at sample.webmastertools.WebmasterToolsClient.insertSite(WebmasterToolsClient.java:183)
    at sample.webmastertools.WebmasterToolsClient.main(WebmasterToolsClient.java:449)

我知道代码与我的帐户进行通信,因为我还运行了printUserSites()功能,该功能会打印网站管理员帐户下的所有网站。

有人可以帮我弄清楚这里发生了什么吗?

1 个答案:

答案 0 :(得分:0)

尝试http://yoursite.com而不是yoursite.com