[f-spot: 2/14] Extended Permissions replaces 'Infinite Session'



commit 4e8ef64edeb21b3b78d40b53cca83a16d7e975d2
Author: Jim Ramsay <i am jimramsay com>
Date:   Tue Jun 23 16:07:50 2009 -0400

    Extended Permissions replaces 'Infinite Session'

 .../Mono.Facebook/FacebookSession.cs               |   21 +++++++++++++-
 .../Exporters/FacebookExport/Mono.Facebook/Util.cs |   29 +++++++++++++++++---
 2 files changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/extensions/Exporters/FacebookExport/Mono.Facebook/FacebookSession.cs b/extensions/Exporters/FacebookExport/Mono.Facebook/FacebookSession.cs
index dc973e5..85d1c47 100644
--- a/extensions/Exporters/FacebookExport/Mono.Facebook/FacebookSession.cs
+++ b/extensions/Exporters/FacebookExport/Mono.Facebook/FacebookSession.cs
@@ -73,9 +73,26 @@ namespace Mono.Facebook
 			return new Uri (string.Format ("http://www.facebook.com/login.php?api_key={0}&v=1.0&auth_token={1}";, util.ApiKey, auth_token));
 		}
 
-		public Uri GetUriForInfiniteToken()
+		public Uri GetGrantUri (string permission)
 		{
-			return new Uri(string.Format("http://www.facebook.com/code_gen.php?v=1.0&api_key={0}";, util.ApiKey));
+			return new Uri(string.Format("http://www.facebook.com/authorize.php?api_key={0}&v=1.0&ext_perm={1}";, util.ApiKey, permission));
+		}
+
+		public bool HasAppPermission(string permission)
+		{
+			return util.GetBoolResponse("facebook.users.hasAppPermission",
+				FacebookParam.Create ("call_id", DateTime.Now.Ticks),
+				FacebookParam.Create ("session_key", session_info.SessionKey),
+				FacebookParam.Create ("ext_perm", permission));
+		}
+
+		public bool RevokeAppPermission(string permission)
+		{
+			return util.GetBoolResponse
+				("facebook.auth.revokeExtendedPermission",
+					FacebookParam.Create ("call_id", DateTime.Now.Ticks),
+					FacebookParam.Create ("session_key", session_info.SessionKey),
+					FacebookParam.Create ("perm", permission));
 		}
 
 		public SessionInfo GetSession ()
diff --git a/extensions/Exporters/FacebookExport/Mono.Facebook/Util.cs b/extensions/Exporters/FacebookExport/Mono.Facebook/Util.cs
index 43dc7a3..0502ae8 100644
--- a/extensions/Exporters/FacebookExport/Mono.Facebook/Util.cs
+++ b/extensions/Exporters/FacebookExport/Mono.Facebook/Util.cs
@@ -89,14 +89,35 @@ namespace Mono.Facebook
 				T response = (T)response_serializer.Deserialize(new MemoryStream(response_bytes));
 				return response;
 			}
-			catch (Exception outer) {
+			catch (InvalidOperationException e) {
 				Error error;
 				try {
 					error = (Error) ErrorSerializer.Deserialize (new MemoryStream (response_bytes));
+				} catch {
+					throw e;
 				}
-				catch {
-					Console.Error.Write (outer.ToString());
-					throw new FacebookException (-1, "Internal error: Could not parse facebook response");
+				throw new FacebookException (error.ErrorCode, error.ErrorMsg);
+			}
+		}
+
+		public bool GetBoolResponse (string method_name, params FacebookParam[] parameters)
+		{
+			string url = FormatGetUrl (method_name, parameters);
+			byte[] response_bytes = GetResponseBytes (url);
+
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (Encoding.Default.GetString (response_bytes));
+
+			try {
+				return System.Convert.ToBoolean(Int32.Parse(doc.InnerText));
+			}
+			catch (FormatException e) {
+				Error error;
+				try {
+					error = (Error) ErrorSerializer.Deserialize (new MemoryStream (response_bytes));
+				} catch {
+					Console.Error.WriteLine("Parse error: Inner text was '{0}'", doc.InnerText);
+					throw e;
 				}
 				throw new FacebookException (error.ErrorCode, error.ErrorMsg);
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]