Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I actually did a project that did something like this before, only it used Google Reader, although I'm assuming the Google authorization process is the same.</p> <p>First off, for each key/value pair in the response you get from logging in, you have to turn that into a cookie.</p> <pre><code>string loginResponseText = new StreamReader(loginResponse.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")); } </code></pre> <p>Then, you have to set the cookie container for the request you're making.</p> <pre><code>string url = string.Format("http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key={0}&amp;fmcmd=4", documentID); HttpWebRequest rqForFile = (HttpWebRequest)WebRequest.Create(url); rqForFile.CookieContainer = cookies; WebResponse respForFile = rUnread.GetResponse(); </code></pre> <p>Enjoy!</p> <p><strong>EDIT</strong>: how to decode the returned HTML!</p> <p>You need to use a Regex to parse out the URL, then use a method to HTML-decode it. Fortunately for us, Microsoft provides one in System.Web. Just add the reference to it to your project.</p> <p>Make sure to add using System.Text.RegularExpressions to the top of your file!</p> <pre><code>Match m = Regex.Match("content=\"0; url=&amp;#39;(.+)&amp;#39;"); if (!m.Success) throw new Exception(); // Or some other method of making sure the result is okay. string finalurl = m.Groups[1].ToString(); finalurl = System.Web.HttpUtility.HtmlDecode(finalurl); </code></pre> <p>Then just fetch finalurl using your CookieContianer! (This is untested, but should work!)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload