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

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

我试图通过编写一个小型 Java 程序来将网站添加到网站管理员帐户并验证它们,从而使我的生活更轻松。

我正在使用 google 在其 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() 函数,该函数打印网站管理员帐户下的所有网站。

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

最佳答案

尝试使用http://yoursite.com而只是 yoursite.com

关于java - 使用 Google API 将网站添加到 Google 网站管理员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286073/

相关文章:

java - Spring - JMS,如何在应用程序启动后启动 JMS 并在应用程序关闭时不断尝试重新连接

java - 删除我的 json 字符串中添加的转义字符

java - 如何在小程序上绕角旋转矩形?

java - 如果主机不存在,SocketChannel 的 connect 方法将保持挂起状态

python - 在 Django 中过滤单个对象的反向关系

python - 是否可以通过 API 检索 Facebook 照片的替代文本?

java - 易于使用的 Web API 即可开始使用

google-apps-script - Google Classroom API - 权限被拒绝

python - 如何在 Google 协作环境中使用 Google Search Console API?

google-api - 有什么方法可以验证BigQuery API中的查询