diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-10 21:19:09 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-10 21:19:09 -0700 |
commit | 5cb3aa5dda4d090400e6561c6ec64999ed5fca4c (patch) | |
tree | 0cf5633163de5d2f4e61c4e4a1c1d3783f234e5f /samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs | |
parent | 8254a5ca1ced42181eb33e1282cfab5e429b0243 (diff) | |
parent | 3588b38fff5216468485d75642f91d283208c5c8 (diff) | |
download | DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.zip DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.gz DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.bz2 |
Merge commit 'v3.0'
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs')
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs new file mode 100644 index 0000000..2a98ffe --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------- +// <copyright file="TwitterConsumer.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using System.Collections.Generic; + using System.IO; + using System.Xml; + using System.Xml.Linq; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth; + using DotNetOpenAuth.OAuth.ChannelElements; + + /// <summary> + /// A consumer capable of communicating with Twitter. + /// </summary> + public static class TwitterConsumer { + /// <summary> + /// The description of Twitter's OAuth protocol URIs. + /// </summary> + public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription { + RequestTokenEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/request_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), + UserAuthorizationEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/authorize", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), + AccessTokenEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/access_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), + TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, + }; + + /// <summary> + /// The URI to get a user's favorites. + /// </summary> + private static readonly MessageReceivingEndpoint GetFavoritesEndpoint = new MessageReceivingEndpoint("http://twitter.com/favorites.xml", HttpDeliveryMethods.GetRequest); + + /// <summary> + /// The URI to get the data on the user's home page. + /// </summary> + private static readonly MessageReceivingEndpoint GetFriendTimelineStatusEndpoint = new MessageReceivingEndpoint("http://twitter.com/statuses/friends_timeline.xml", HttpDeliveryMethods.GetRequest); + + public static XDocument GetUpdates(ConsumerBase twitter, string accessToken) { + IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken); + return XDocument.Load(XmlReader.Create(response.GetResponseReader())); + } + + public static XDocument GetFavorites(ConsumerBase twitter, string accessToken) { + IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFavoritesEndpoint, accessToken); + return XDocument.Load(XmlReader.Create(response.GetResponseReader())); + } + } +} |