2013-10-11 41 views
6

我一直抨擊我的這幾天,現在試圖找出如何做到這一點。我想從Google網站管理員工具中下載我已成功完成的CSV。但是,我必須直接傳遞我希望訪問的帳戶的用戶名和密碼。對於網站管理員工具的所有其他方面,我只需要用戶登錄,然後使用可重複使用的會話令牌交換令牌。Java谷歌網站管理員熱門查詢

我似乎無法使用此方法來獲取查詢數據。

String next = "http://xyz.domain.com/auth"; //sets page to goto after user log's in so we can pass the token to application 
String scope = "http://www.google.com/webmasters/tools/feeds"; // sets the scope of the token 
boolean secure = false; 
boolean session = true; 
String urlFromAuthSub = AuthSubUtil.getRequestUrl(next, scope, secure, session); //generates the URL to forward user to loginto google. 

在您的捕獲頁面(上面代碼中的下一個參數)成功登錄後您會收到令牌。然後您將它交換爲會話令牌。

String token = "##########################"; 
String sessionToken = AuthSubUtil.exchangeForSessionToken(token, null); 
//store sessionToken for all future use to interact with webmaster for this user. 

於是最後我們簡單地創建我們WebmasterToolsService對象,並設置它的AuthSubToken到會話令牌,並完成了!

WebmasterToolsService myService = new WebmasterToolsService("DemoWebmaster"); 
myService.setAuthSubToken(token); 

但是,當試圖下載CSV時,我別無選擇,只能使用Google用戶的完整憑據。

String host = "www.google.com"; 
String dl_list_url = "/webmasters/tools/downloads-list?hl=%s&siteUrl=%s"; 
String sites_path = "/webmasters/tools/feeds/sites/"; 
WebmasterToolsService svc = new WebmasterToolsService("DemoQuery Service"); 
svc.setUserCredentials("[email protected]", "123456"); 

之後,我可以做任何與網站管理員API,因爲我通過完整的客戶端登錄。但是,對於我正在構建的應用程序,我不需要存儲用戶完整的Google憑據。

我看到一家公司設法在添加Google網站管理員API時以某種方式將此關閉。但我似乎看不出有可能如何。有任何想法嗎?

回答

1

關於這樣做的公司,他們是誰,他們是否提供某種公共工具或混搭?可能他們只是使用一些不公平的手段來保存你的數據。你有網址嗎?

據我所知(我知道進一步的研究以防萬一)這是不可能的。 有幾件事:

  1. 正如你所說,google's example in python使用用戶名和密碼。
  2. eyecatchup php-webmaster-tools-downloads library,還需要用戶名和密碼。
  3. 如果您訪問Google API控制檯(https://code.google.com/apis/consolehttps://cloud.google.com/console),網站管理員工具API不存在,所以似乎不像所有其他apis一樣使用通用權限系統。

所以,我恐怕你不會是幸運的。

相關問題