summaryrefslogtreecommitdiffstats
path: root/samples/DotNetOpenAuth.ApplicationBlock
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-01-11 09:50:07 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2010-01-11 20:38:34 -0800
commitebb410df2ce3cb1884c0f264b0391dcbae290db1 (patch)
tree8aa6d640ec5a9fcdd5a78688cef022be593776a4 /samples/DotNetOpenAuth.ApplicationBlock
parent83ff5ac2e46759ab588a0a8ae165b6544ce36290 (diff)
downloadDotNetOpenAuth-ebb410df2ce3cb1884c0f264b0391dcbae290db1.zip
DotNetOpenAuth-ebb410df2ce3cb1884c0f264b0391dcbae290db1.tar.gz
DotNetOpenAuth-ebb410df2ce3cb1884c0f264b0391dcbae290db1.tar.bz2
Updated TwitterConsumer sample in the ApplicationBlock to include profile image upload.
Added an Upload Photo button to the Twitter sample page.
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
index 2a98ffe..ba7fbfb 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
@@ -8,6 +8,7 @@ namespace DotNetOpenAuth.ApplicationBlock {
using System;
using System.Collections.Generic;
using System.IO;
+ using System.Net;
using System.Xml;
using System.Xml.Linq;
using DotNetOpenAuth.Messaging;
@@ -38,6 +39,18 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// </summary>
private static readonly MessageReceivingEndpoint GetFriendTimelineStatusEndpoint = new MessageReceivingEndpoint("http://twitter.com/statuses/friends_timeline.xml", HttpDeliveryMethods.GetRequest);
+ private static readonly MessageReceivingEndpoint UpdateProfileBackgroundImageEndpoint = new MessageReceivingEndpoint("http://twitter.com/account/update_profile_background_image.xml", HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
+
+ private static readonly MessageReceivingEndpoint UpdateProfileImageEndpoint = new MessageReceivingEndpoint("http://twitter.com/account/update_profile_image.xml", HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
+
+ /// <summary>
+ /// Initializes the <see cref="TwitterConsumer"/> class.
+ /// </summary>
+ static TwitterConsumer() {
+ // Twitter can't handle the Expect 100 Continue HTTP header.
+ ServicePointManager.FindServicePoint(GetFavoritesEndpoint.Location).Expect100Continue = false;
+ }
+
public static XDocument GetUpdates(ConsumerBase twitter, string accessToken) {
IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken);
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
@@ -47,5 +60,32 @@ namespace DotNetOpenAuth.ApplicationBlock {
IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFavoritesEndpoint, accessToken);
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
}
+
+ public static XDocument UpdateProfileBackgroundImage(ConsumerBase twitter, string accessToken, string image, bool tile) {
+ HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateProfileBackgroundImageEndpoint, accessToken);
+ request.ServicePoint.Expect100Continue = false;
+ var parts = new [] {
+ MultipartPostPart.CreateFormFilePart("image", image, "image/" + Path.GetExtension(image).Substring(1).ToLowerInvariant()),
+ MultipartPostPart.CreateFormPart("tile", tile.ToString().ToLowerInvariant()),
+ };
+ IncomingWebResponse response = request.PostMultipart(twitter.Channel.WebRequestHandler, parts);
+ string responseString = response.GetResponseReader().ReadToEnd();
+ return XDocument.Parse(responseString);
+ }
+
+ public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, string pathToImage) {
+ string contentType = "image/" + Path.GetExtension(pathToImage).Substring(1).ToLowerInvariant();
+ return UpdateProfileImage(twitter, accessToken, File.OpenRead(pathToImage), contentType);
+ }
+
+ public static XDocument UpdateProfileImage(ConsumerBase twitter, string accessToken, Stream image, string contentType) {
+ HttpWebRequest request = twitter.PrepareAuthorizedRequest(UpdateProfileImageEndpoint, accessToken);
+ var parts = new[] {
+ MultipartPostPart.CreateFormFilePart("image", "twitterPhoto", contentType, image),
+ };
+ IncomingWebResponse response = request.PostMultipart(twitter.Channel.WebRequestHandler, parts);
+ string responseString = response.GetResponseReader().ReadToEnd();
+ return XDocument.Parse(responseString);
+ }
}
}