Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login Remotely To Google Analytics with ASP.NET

I'm trying to login directly to Google Analytics. To explain, I have an account system and I'd like when you select an ASP.NET button for instance it re-directs you - via a silent login - to a specified Google Analytics account.

I've looked long and hard at Dave Cullen's ASP.NET library and although I can login 'silently' using HttpWebRequest, I can't then stick the user on that page. I'm having allsorts of dramas with a 'Cannot send a content-body with this verb-type' error too.

Here is the very basic code I have currently based on Dave's library;

 string token = GoogleAnalytics.getSessionTokenClientLogin(username, password);
    NameValueCollection profiles = GoogleAnalytics.getAccountInfo(token, GoogleAnalytics.mode.ClientLogin);

    HttpWebRequest theRequest = (HttpWebRequest)WebRequest.Create("https://www.google.com/analytics/settings/?et=reset&hl=en_uk&et=reset&hl=en-US&et=reset&hl=en-GB");
    theRequest.Headers.Add("Authorization: GoogleLogin auth=" + token);
    Stream responseBody = theRequest.GetRequestStream();
    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    StreamReader readStream = new StreamReader(responseBody, encode);

My question therefore is; 1. can this be done? and 2. is this even the right way to do this?

Advice welcomed!

like image 951
dooburt Avatar asked Jul 28 '09 15:07

dooburt


1 Answers

I'm not sure what the overall goal of signing someone in to Google Analytics automatically is, but if its just to display some of the data that is in Google Analytics you might want to consider using the Google Data API to pull the information that you want from Google Analytics. You could create a simple dashboard of what they really need to see without giving access to other things in Google Analytics, by logging them in you are most likely giving them access to data and tools that they just don't need?

Check out the API if it doesn't fit your needs maybe provide some more information on the overall goal is of this functionality.

http://code.google.com/apis/analytics/

like image 161
YetAnotherDeveloper Avatar answered Oct 10 '22 19:10

YetAnotherDeveloper