2013-10-10 149 views
1

我試圖通過編寫一個小型的Java程序,將網站添加到網站管理員帳戶並進行驗證,從而使我的生活更輕鬆。使用Google API爲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()功能,可以在網站管理員帳戶下打印所有網站。

有人能幫我弄清楚這裏發生了什麼嗎?

回答

相關問題