【问题标题】:Java google webmaster top queriesJava google 站长热门查询
【发布时间】:2013-10-11 02:22:36
【问题描述】:

这几天我一直在为此苦苦挣扎,试图弄清楚这是怎么做到的。我想从我已经成功完成的谷歌网站管理员工具下载 CSV。但是,我必须直接传递我希望访问的帐户的用户名和密码。对于网站管理员工具的所有其他方面,我只需让用户登录,然后将登录时的令牌与可重复使用的会话令牌交换。

在获取查询数据时,我似乎无法使用此方法。

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("xyz@domain.com", "123456");

之后,当我通过完整的客户端登录时,我可以使用网站管理员 API 执行任何操作。但是,对于我正在构建的应用程序,我不需要存储用户的完整 Google 凭据。

当您添加 Google 网站管理员 API 时,我看到一家公司设法以某种方式实现了这一目标。但我似乎看不出这是怎么可能的。有什么想法吗?

【问题讨论】:

    标签: java google-search-console


    【解决方案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 不存在,因此它似乎不像所有其他 API 那样使用通用权限系统。

    所以,恐怕你不会走运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      相关资源
      最近更新 更多