diff options
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs | 12 | ||||
-rw-r--r-- | samples/OAuthConsumer/GoogleAddressBook.aspx | 2 | ||||
-rw-r--r-- | samples/OAuthConsumer/GoogleAddressBook.aspx.cs | 2 |
3 files changed, 12 insertions, 4 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs index 4d3ce13..2add642 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs @@ -8,6 +8,7 @@ namespace DotNetOpenAuth.ApplicationBlock { using System; using System.Collections.Generic; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -208,13 +209,20 @@ namespace DotNetOpenAuth.ApplicationBlock { /// </summary> /// <param name="consumer">The Google consumer previously constructed using <see cref="CreateWebConsumer"/> or <see cref="CreateDesktopConsumer"/>.</param> /// <param name="accessToken">The access token previously retrieved.</param> + /// <param name="maxResults">The maximum number of entries to return. If you want to receive all of the contacts, rather than only the default maximum, you can specify a very large number here.</param> + /// <param name="startIndex">The 1-based index of the first result to be retrieved (for paging).</param> /// <returns>An XML document returned by Google.</returns> - public static XDocument GetContacts(ConsumerBase consumer, string accessToken) { + public static XDocument GetContacts(ConsumerBase consumer, string accessToken, int maxResults = 25, int startIndex = 1) { if (consumer == null) { throw new ArgumentNullException("consumer"); } - var response = consumer.PrepareAuthorizedRequestAndSend(GetContactsEndpoint, accessToken); + var extraData = new Dictionary<string, string>() { + { "start-index", startIndex.ToString(CultureInfo.InvariantCulture) }, + { "max-results", maxResults.ToString(CultureInfo.InvariantCulture) }, + }; + var request = consumer.PrepareAuthorizedRequest(GetContactsEndpoint, accessToken, extraData); + var response = consumer.Channel.WebRequestHandler.GetResponse(request); string body = response.GetResponseReader().ReadToEnd(); XDocument result = XDocument.Parse(body); return result; diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx b/samples/OAuthConsumer/GoogleAddressBook.aspx index 1be21aa..19fb505 100644 --- a/samples/OAuthConsumer/GoogleAddressBook.aspx +++ b/samples/OAuthConsumer/GoogleAddressBook.aspx @@ -16,7 +16,7 @@ <asp:View runat="server"> <h2>Updates</h2> <p>Ok, Google has authorized us to download your contacts. Click 'Get address book' - to download the first 25 contacts to this sample. Notice how we never asked you + to download the first 5 contacts to this sample. Notice how we never asked you for your Google username or password. </p> <asp:Button ID="getAddressBookButton" runat="server" OnClick="getAddressBookButton_Click" Text="Get address book" /> diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs index 808065f..1ca3abe 100644 --- a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs +++ b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs @@ -57,7 +57,7 @@ protected void getAddressBookButton_Click(object sender, EventArgs e) { var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); - XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.AccessToken); + XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.AccessToken, 5); 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(); |