【问题标题】:Adding site to Google Webmaster using Google API使用 Google API 将网站添加到 Google 网站管理员
【发布时间】:2013-10-10 02:31:56
【问题描述】:

我正在尝试通过编写一个小型 Java 程序来将网站添加到网站管理员帐户并对其进行验证,从而让我的生活更轻松。

我正在使用谷歌在他们的 api 文档中的示例代码:

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() 函数,该函数打印了网站管理员帐户下的所有网站。

谁能帮我弄清楚这里发生了什么?

【问题讨论】:

    标签: java api google-api google-search-console


    【解决方案1】:

    尝试使用http://yoursite.com,而不是仅使用 yoursite.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      相关资源
      最近更新 更多