Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java google webmaster top queries

I have been bashing my head on this for days now trying to figure out how this is possible to do. I want to download the CSV's from Google Webmaster Tools which I have succeed in doing. However, I have to directly pass the username and password of the account I wish to access. For all other aspects of the webmaster tools, I simply have the user login and I exchange the token from there login with a re-useable session token.

I cant seem to use this method when it comes to getting the query data.

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.

On your capture page (the next parameter in the code above) you receive the token after successful login. Then you exchange it for the session token.

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

Then finally we simply create our WebmasterToolsService object and set it's AuthSubToken to the session token, and DONE!

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

However when trying to download the CSV, I have no choice but to use full credentials of the Google user.

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");

After that I can do anything with the webmaster API as I am passing the full client login. However, for the application I am building, I need to not store the users full Google credentials.

I seen one company that has managed to pull this off somehow when you add the Google webmaster API. But I cant seem to see how it is possible. Any ideas?

like image 661
drankupon Avatar asked Oct 11 '13 02:10

drankupon


1 Answers

About that company that is doing it, who are they, are they giving some kind of public tool or mashup? Probably they are just using some unfair trick to keep your data. Do you have an URL?

As far as i know (and i did know a further research just in case) that's not possible. for a few things:

  1. As you say, google's example in python uses username and password.
  2. eyecatchup php-webmaster-tools-downloads library, also requires username and password.
  3. If you go to the Google APIs Console (https://code.google.com/apis/console or https://cloud.google.com/console) the Webmaster Tools API is not present, so it doesn't seems like using the common permission system as all the other apis does.

So, i am afraid you wont be lucky.

like image 101
Carlos Robles Avatar answered Sep 28 '22 08:09

Carlos Robles