I am testing by this code.
Is this wrong ?

--------------------------------------------------------------------------------------------
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    Label1.Text = Request["token"];
  }
}

protected void Button1_Click(object sender, EventArgs e)
{
  string self = Request.Url.Scheme + "://"
              + Request.Url.Authority + Request.Url.AbsolutePath;

  Response.Redirect(

string.Format("https://www.google.com/accounts/AuthSubRequest?next={0}&scope={1}&session=1&secure=0";,
      Server.UrlEncode(self),
      Server.UrlEncode("https://www.google.com/calendar/feeds/";))
  );
}

protected void Button2_Click(object sender, EventArgs e)
{
  string s =
HttpGetWithAuthSub("https://www.google.com/accounts/AuthSubSessionToken";,
Label1.Text);

  Regex regex = new Regex("^Token=(.*)$", RegexOptions.Multiline);
  if (regex.IsMatch(s))
  {
    Label2.Text = regex.Match(s).Groups[1].Value;
  }
}

protected void Button3_Click(object sender, EventArgs e)
{

HttpGetWithAuthSub("https://www.google.com/accounts/AuthSubTokenInfo";,
Label2.Text);
}

protected void Button4_Click(object sender, EventArgs e)
{

HttpGetWithAuthSub("https://www.google.com/calendar/feeds/default/private/full";,
Label2.Text);
}

protected void Button5_Click(object sender, EventArgs e)
{
  HttpGetWithAuthSub("https://www.google.com/calendar/feeds/default";,
Label2.Text);
}

protected void Button6_Click(object sender, EventArgs e)
{

HttpGetWithAuthSub("https://www.google.com/accounts/AuthSubRevokeToken";,
Label2.Text);
  Label1.Text = string.Empty;
  Label2.Text = string.Empty;
}

private string HttpGetWithAuthSub(string url, string token)
{
  try
  {
    Pre1.InnerText = string.Empty;

    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
    req.Headers["Authorization"] = string.Format("AuthSub
token=\"{0}\"", token);
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

    string body = new
StreamReader(res.GetResponseStream()).ReadToEnd();

    Pre1.InnerText = (int)res.StatusCode + " " + res.StatusDescription;
    Pre2.InnerText = res.Headers.ToString();
    Pre3.InnerText = body;

    return body;
  }
  catch (WebException ex)
  {
    HttpWebResponse res = (HttpWebResponse)ex.Response;

    Pre1.InnerText = (int)res.StatusCode + " " + res.StatusDescription;
    Pre2.InnerText = res.Headers.ToString();
    Pre3.InnerHtml = new
StreamReader(res.GetResponseStream()).ReadToEnd();

    return string.Empty;
  }
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml"; >
<head id="Head1" runat="server">
    <title>AuthSubTest</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    1. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Get single token" />
    <asp:Label ID="Label1" runat="server"></asp:Label><br />
    <br />
    2. <asp:Button ID="Button2" runat="server" Text="Get session token"
OnClick="Button2_Click" />
    <asp:Label ID="Label2" runat="server"></asp:Label><br />
    <br />
    3. <asp:Button ID="Button3" runat="server" OnClick="Button3_Click"
Text="Get token info" />
    <asp:Button ID="Button4" runat="server" OnClick="Button4_Click"
Text="Get events" />
    <asp:Button ID="Button5" runat="server" OnClick="Button5_Click"
Text="Get list of calendars" /><br />
    <br />
    4. <asp:Button ID="Button6" runat="server" OnClick="Button6_Click"
Text="Revoke token" /><br />
    <hr />
    <pre runat="server" id="Pre1"></pre>
    <pre runat="server" id="Pre2"></pre>
    <pre runat="server" id="Pre3"></pre>
    </div>
    </form>
</body>
</html>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi
-~----------~----~----~----~------~----~------~--~---

Reply via email to