Hi,

Using the cookie like that won't work. Especially as you are using the
cookie for www.google.com against a spreadsheets.google.com address,
but even with the correct domain it would not work.

You should use the Google Documents List API [1] to programmatically
export the spreadsheet. If you have any questions about this, you
should post them on the Documents List API forum [2].

Regards


[1] 
http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html
[2] http://code.google.com/apis/documents/forum.html

On Tue, Jan 3, 2012 at 11:21 PM, Miro Nikolov <[email protected]> wrote:
> I have been unable to export a spreadsheet file using the code below. All I
> get is the Google Account log in page. I am able to authenticate and store
> the Auth Id in a cookie container. But my second request for the spreadsheet
> only leads me to log in page.
>
>
>
> string str = "/accounts/ClientLogin HTTP/1.0 Content-type:
> application/x-www-form-urlencoded
> accountType=GOOGLE&[email protected]&Passwd=....&service=writely&source=Gulp-CalGulp-1.05";
>
> string uri = "https://www.google.com/accounts/ClientLogin";;
>
> HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
>
> request.KeepAlive =
>
> false;
>
> request.ProtocolVersion =
>
> HttpVersion.Version10;
>
> request.Method =
>
> "POST";
>
> byte[] postBytes = Encoding.ASCII.GetBytes(str);
>
> request.ContentType =
>
> "application/x-www-form-urlencoded";
>
> request.ContentLength = postBytes.Length;
>
> Stream requestStream = request.GetRequestStream();
>
>
>
> requestStream.Write(postBytes, 0, postBytes.Length);
>
> requestStream.Close();
>
> HttpWebResponse response = (HttpWebResponse)request.GetResponse();
>
> string loginResponseText = new
> StreamReader(response.GetResponseStream()).ReadToEnd();
>
> CookieContainer cookies = new CookieContainer();
>
> foreach (string ln in loginResponseText.Split('\n'))
>
> {
>
> if (!ln.Contains("=")) continue;
>
> string tId = ln.Substring(0, ln.IndexOf('=')).Trim();
>
> string tVal = ln.Substring(ln.IndexOf('=') + 1).Trim();
>
> cookies.Add(
>
> new Cookie(tId, tVal, "/", "www.google.com"));
>
> }
>
> string sURL =
> "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=0AuT3EANDSDLAdGc0c1RqaS1jVmM5QVdNMjhhRlNnZVE&exportFormat=csv";;
>
> HttpWebRequest wrGETURL;
>
> wrGETURL = (
>
> HttpWebRequest)WebRequest.Create(sURL);
>
> wrGETURL.CookieContainer = cookies;
>
> wrGETURL.UseDefaultCredentials =
>
> true;
>
> Stream objStream;
>
> objStream = wrGETURL.GetResponse().GetResponseStream();
>
> string sAllLines = "";
>
> StreamReader objreader = new StreamReader(objStream);
>
> sAllLines = objreader.ReadToEnd();



-- 
Ali Afshar | www.googplus.org/ali | Google Developer Relations

Reply via email to