protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(State.GoogleAccessToken)) { this.MultiView1.ActiveViewIndex = 1; if (State.FetchResponse != null && State.FetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email)) { this.emailLabel.Text = State.FetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values[0]; } else { this.emailLabel.Text = "unavailable"; } this.claimedIdLabel.Text = this.User.Identity.Name; var contactsDocument = GoogleConsumer.GetContacts(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1); this.RenderContacts(contactsDocument); } }
private void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(this.googleTokenManager.ConsumerKey)) { MessageBox.Show(this, "You must modify the App.config or OAuthConsumerWpf.exe.config file for this application to include your Google OAuth consumer key first.", "Configuration required", MessageBoxButton.OK, MessageBoxImage.Stop); return; } Authorize auth = new Authorize( this.google, (DesktopConsumer consumer, out string requestToken) => GoogleConsumer.RequestAuthorization( consumer, GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger, out requestToken)); bool?result = auth.ShowDialog(); if (result.HasValue && result.Value) { this.googleAccessToken = auth.AccessToken; this.postButton.IsEnabled = true; XDocument contactsDocument = GoogleConsumer.GetContacts(this.google, this.googleAccessToken, 25, 1); var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom")) select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value }; this.contactsGrid.Children.Clear(); foreach (var contact in contacts) { this.contactsGrid.RowDefinitions.Add(new RowDefinition()); TextBlock name = new TextBlock { Text = contact.Name }; TextBlock email = new TextBlock { Text = contact.Email }; Grid.SetRow(name, this.contactsGrid.RowDefinitions.Count - 1); Grid.SetRow(email, this.contactsGrid.RowDefinitions.Count - 1); Grid.SetColumn(email, 1); this.contactsGrid.Children.Add(name); this.contactsGrid.Children.Add(email); } } }
protected void getAddressBookButton_Click(object sender, EventArgs e) { var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.AccessToken); var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom")) select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value }; StringBuilder tableBuilder = new StringBuilder(); tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>"); foreach (var contact in contacts) { tableBuilder.AppendFormat( "<tr><td>{0}</td><td>{1}</td></tr>", HttpUtility.HtmlEncode(contact.Name), HttpUtility.HtmlEncode(contact.Email)); } tableBuilder.Append("</table>"); resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); }