我一直抨擊我的這幾天,現在試圖找出如何做到這一點。我想從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時以某種方式將此關閉。但我似乎看不出有可能如何。有任何想法嗎?