summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-05-13 20:35:00 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-05-13 20:35:00 -0700
commitb9f5a2bddfb925c308904cc855eb8d02e5c361bf (patch)
treea5706cda0a6822ccae067b345f7928ccd006ae62
parent91b551a888d3cae98cf5f1053c6f5c7141db4a3f (diff)
downloadDotNetOpenAuth-b9f5a2bddfb925c308904cc855eb8d02e5c361bf.zip
DotNetOpenAuth-b9f5a2bddfb925c308904cc855eb8d02e5c361bf.tar.gz
DotNetOpenAuth-b9f5a2bddfb925c308904cc855eb8d02e5c361bf.tar.bz2
Placeholder Facebook Graph API now in the ApplicationBlock, and the sample calls into it.
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj5
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs (renamed from samples/DotNetOpenAuth.ApplicationBlock/FacebookClient.cs)0
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs54
-rw-r--r--samples/OAuthConsumer/Facebook.aspx.cs13
4 files changed, 62 insertions, 10 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
index b8a7623..ffc7357 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
+++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
@@ -72,6 +72,8 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -86,7 +88,8 @@
<Compile Include="CustomExtensions\Acme.cs" />
<Compile Include="CustomExtensions\AcmeRequest.cs" />
<Compile Include="CustomExtensions\AcmeResponse.cs" />
- <Compile Include="FacebookClient.cs" />
+ <Compile Include="Facebook\FacebookClient.cs" />
+ <Compile Include="Facebook\FacebookGraph.cs" />
<Compile Include="GoogleConsumer.cs" />
<Compile Include="InMemoryTokenManager.cs">
<SubType>Code</SubType>
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/FacebookClient.cs b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs
index b7df5dd..b7df5dd 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/FacebookClient.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookClient.cs
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs
new file mode 100644
index 0000000..0e878c1
--- /dev/null
+++ b/samples/DotNetOpenAuth.ApplicationBlock/Facebook/FacebookGraph.cs
@@ -0,0 +1,54 @@
+//-----------------------------------------------------------------------
+// <copyright file="FacebookGraph.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.ApplicationBlock.Facebook {
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Runtime.Serialization;
+ using System.Runtime.Serialization.Json;
+ using System.Text;
+
+ [DataContract]
+ public class FacebookGraph {
+ private static DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(FacebookGraph));
+
+ [DataMember(Name = "id")]
+ public int Id { get; set; }
+
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+ [DataMember(Name = "first_name")]
+ public string FirstName { get; set; }
+
+ [DataMember(Name = "last_name")]
+ public string LastName { get; set; }
+
+ [DataMember(Name = "link")]
+ public Uri Link { get; set; }
+
+ [DataMember(Name = "birthday")]
+ public string Birthday { get; set; }
+
+ public static FacebookGraph Deserialize(string json) {
+ if (String.IsNullOrEmpty(json)) {
+ throw new ArgumentNullException("json");
+ }
+
+ return Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json)));
+ }
+
+ public static FacebookGraph Deserialize(Stream jsonStream) {
+ if (jsonStream == null) {
+ throw new ArgumentNullException("jsonStream");
+ }
+
+ return (FacebookGraph)jsonSerializer.ReadObject(jsonStream);
+ }
+ }
+}
diff --git a/samples/OAuthConsumer/Facebook.aspx.cs b/samples/OAuthConsumer/Facebook.aspx.cs
index 3553f0e..ce191fd 100644
--- a/samples/OAuthConsumer/Facebook.aspx.cs
+++ b/samples/OAuthConsumer/Facebook.aspx.cs
@@ -1,15 +1,10 @@
namespace OAuthConsumer {
using System;
- using System.Collections.Generic;
using System.Configuration;
- using System.IO;
- using System.Linq;
using System.Net;
using System.Web;
- using System.Web.Script.Serialization;
- using System.Web.UI;
- using System.Web.UI.WebControls;
using DotNetOpenAuth.ApplicationBlock;
+ using DotNetOpenAuth.ApplicationBlock.Facebook;
using DotNetOpenAuth.OAuthWrap;
public partial class Facebook : System.Web.UI.Page {
@@ -26,11 +21,11 @@
} else {
var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse()) {
- using (var responseReader = new StreamReader(response.GetResponseStream())) {
- string data = responseReader.ReadToEnd();
+ using (var responseStream = response.GetResponseStream()) {
+ var graph = FacebookGraph.Deserialize(responseStream);
+ nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
}
}
- nameLabel.Text = "Success! Access token: " + HttpUtility.HtmlEncode(authorization.AccessToken);
}
}
}