Switch over to System.Web.Script.Serialization, "finish" up support for deserializing the "User" object (users.getInfo) from Facebook.
UIDs are forced over as strings, it seems that converting to Int64 on a 32-bit environment throws an exception in Convert.ChangeType() (to investigate further after the patch to 328836 is committed) svn path=/trunk/facebook-sharp/; revision=87454
This commit is contained in:
Родитель
5a4b8db4f6
Коммит
2e4e11c68b
|
@ -37,21 +37,7 @@
|
|||
</sources>
|
||||
<references>
|
||||
<include name="System.Web.dll"/>
|
||||
<include name="${contrib_dir}/Newtonsoft.Json.dll"/>
|
||||
</references>
|
||||
</csc>
|
||||
</target>
|
||||
|
||||
<target name="json.net" description="Build Json.NET for Mono.Facebook.Platform">
|
||||
<echo message="Building Json.NET"/>
|
||||
|
||||
<csc target="library" output="${bin_dir}/Newtonsoft.Json.dll">
|
||||
<sources>
|
||||
<include name="contrib/Newtonsoft.Json/**.cs"/>
|
||||
</sources>
|
||||
<references>
|
||||
<include name="System.Web.dll"/>
|
||||
|
||||
<include name="System.Web.Extensions.dll"/>
|
||||
</references>
|
||||
</csc>
|
||||
</target>
|
||||
|
|
|
@ -23,5 +23,16 @@ namespace Mono.Facebook.Platform
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class EmptyDataSetException : Exception
|
||||
{
|
||||
public EmptyDataSetException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public EmptyDataSetException(string mesg) : base(mesg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,52 @@
|
|||
using System;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Mono.Facebook.Platform
|
||||
{
|
||||
public class User
|
||||
{
|
||||
/*
|
||||
* Because System.Web.Script.Serialization sucks, and doesn't allow for specifying
|
||||
* [JsonElement()] style attributes, forgive the terrible style of using public member
|
||||
* variables, vomit.
|
||||
*/
|
||||
#region "Member Variables"
|
||||
public string uid;
|
||||
public string name;
|
||||
public string about_me;
|
||||
public string activities;
|
||||
public DateTime birthday;
|
||||
public string books;
|
||||
public string interests;
|
||||
public bool is_app_user;
|
||||
public string first_name;
|
||||
public string last_name;
|
||||
public Nullable<int> notes_count;
|
||||
public string pic;
|
||||
public string pic_big;
|
||||
public string pic_small;
|
||||
public string pic_square;
|
||||
public string quotes;
|
||||
public string religion;
|
||||
public string sex;
|
||||
public string significant_other_id;
|
||||
public Nullable<int> timezone;
|
||||
public string tv;
|
||||
public Nullable<int> wall_count;
|
||||
public bool has_added_app;
|
||||
#endregion
|
||||
|
||||
#region "Constructors"
|
||||
public User()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region "Public Methods"
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("UID: {0}, Name: {1}", Convert.ToInt64(uid), name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Mono.Facebook.Platform
|
||||
{
|
||||
public class Users
|
||||
{
|
||||
#region "Public Static Member Variables"
|
||||
public static readonly string[] DefaultFields = new string[]{"uid", "about_me", "activities", "affiliations", "birthday", "books", "current_location", "education_history",
|
||||
"first_name", "last_name", "has_added_app", "hometown_location", "hs_info", "interests", "is_app_user", "meeting_for",
|
||||
"meeting_sex", "movies", "music", "name", "notes_count", "pic", "pic_small", "pic_square", "pic_big", "political",
|
||||
"profile_update_time", "quotes", "relationship_status", "religion", "sex", "significant_other_id", "status", "timezone",
|
||||
"tv", "wall_count", "work_history"};
|
||||
#endregion
|
||||
|
||||
#region "Public Static Methods (Facebook)"
|
||||
public static bool IsAppAdded()
|
||||
{
|
||||
|
@ -14,24 +22,33 @@ namespace Mono.Facebook.Platform
|
|||
|
||||
if (Facebook.Instance.Format == ResponseType.Json)
|
||||
{
|
||||
return JavaScriptConvert.DeserializeObject<bool>(response);
|
||||
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
||||
return serializer.Deserialize<bool>(response);
|
||||
}
|
||||
|
||||
throw new NotImplementedException("Looks like that call isn't supported yet");
|
||||
}
|
||||
|
||||
public static void GetInfo(string[] fields)
|
||||
public static User GetInfo()
|
||||
{
|
||||
GetInfo(new string[]{Facebook.Instance.Session.Uid.ToString()}, fields);
|
||||
List<User> users = GetInfo(DefaultFields);
|
||||
if (users.Count > 0)
|
||||
return users[0];
|
||||
else
|
||||
throw new EmptyDataSetException("Facebook returned an empty user-set");
|
||||
}
|
||||
public static void GetInfo(List<long> uids, List<string> fields)
|
||||
public static List<User> GetInfo(string[] fields)
|
||||
{
|
||||
return GetInfo(new string[]{Facebook.Instance.Session.Uid.ToString()}, fields);
|
||||
}
|
||||
public static List<User> GetInfo(List<long> uids, List<string> fields)
|
||||
{
|
||||
string[] _uids = Array.ConvertAll<long, string>(uids.ToArray(), delegate(long uid) { return uid.ToString(); });
|
||||
string[] _fields = fields.ToArray();
|
||||
|
||||
GetInfo(_uids, _fields);
|
||||
return GetInfo(_uids, _fields);
|
||||
}
|
||||
public static void GetInfo(string[] uids, string[] fields)
|
||||
public static List<User> GetInfo(string[] uids, string[] fields)
|
||||
{
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||||
|
||||
|
@ -40,7 +57,14 @@ namespace Mono.Facebook.Platform
|
|||
|
||||
string response = Facebook.Instance.MakeRequest("users.getInfo", parameters);
|
||||
|
||||
Console.WriteLine(response);
|
||||
if (Facebook.Instance.Format == ResponseType.Json)
|
||||
{
|
||||
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
||||
Console.WriteLine(response);
|
||||
return serializer.Deserialize<List<User>>(response);
|
||||
}
|
||||
|
||||
throw new NotImplementedException("Looks like that call isn't supported yet");
|
||||
}
|
||||
|
||||
public static long GetLoggedInUser()
|
||||
|
@ -49,7 +73,8 @@ namespace Mono.Facebook.Platform
|
|||
|
||||
if (Facebook.Instance.Format == ResponseType.Json)
|
||||
{
|
||||
return JavaScriptConvert.DeserializeObject<Int64>(response);
|
||||
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
||||
return serializer.Deserialize<Int64>(response);
|
||||
}
|
||||
|
||||
throw new NotImplementedException("Looks like that call isn't supported yet");
|
||||
|
|
Загрузка…
Ссылка в новой задаче