FQL query returning string

Jan 10, 2009 at 6:46 AM
I am trying to grab a list of the user's friends.
The code I use is:

q.query("SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + myUID + ")");

where myUID is an int variable that holds the end user's facebook userID.

The result I get is a string type with the information I want in one single string.  Is there a function that returns an array or IList?  Or do I need to just separate them by spaces via my own code?
Currently I am using C#, ASP.NET, and the Microsoft Codeplex assemblies

Any help would be appreciated!


Aug 18, 2009 at 3:34 AM

I also have problem with this. I look at the source code and the author uses XTypedServices to cast XML to .NET Object but I don't have enough experience to make it works with FQL query string too.

Let hope this will be improved in next release.


Aug 21, 2009 at 8:30 AM
Edited Aug 21, 2009 at 9:48 AM

What do you need to do with them, I just put mine into a dataset.

Sep 17, 2009 at 1:31 PM
Edited Sep 17, 2009 at 5:12 PM

I'm going to use the original query to provide an example here for anyone else wishing to do this kind of stuff.

Via C#


using System.Xml;

FacebookService fBookServ = new FacebookService();

string temp_string = q.query("SELECT uid, first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + myUID + ")");

string yourQueryString = fBookServ.fql.query(temp_string);

XmlDocument xmlDoc = new XmlDocument();


XmlNodeList uidList = xmlDoc.GetElementsByTagName("uid");

XmlNodeList firstNList = xmlDoc.GetElementsByTagName("first_name");

XmlNodeList lastNList = xmlDoc.GetElementsByTagName("last_name");

//At this point you should have all of your information. To access it
//do the following

string uid = "";
foreach (XmlNode node in uidList)
if (!String.IsNullOrEmpty(node.InnerText)) {
uid = node.InnerText;

//Obviously the above code really doesn't do anything, but it
//shows you how to access the data.


Hope this helps. Enjoy.

Kevin F.



Sep 18, 2009 at 7:01 PM

In the 3.0 code, there is a generic override for fql.query where you can pass in the type and it will deserialize for you.


The caveat is that you need to use a type that will match the fql result you are getting back.  For all the cases I have run into, you can use one of the response classes like users_GetInfo_response


And it will give you the strongly typed object that was returned by the fql.  You can see this used by many of the classes in the BindingHelper namespace.

Sep 20, 2009 at 2:46 PM

You could also use Linq to Xml:

using System.Xml.Linq;

var response = facebookAPI.fql.query(String.Format("SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {0}) ORDER BY name", api.uid));

XDocument xml = XDocument.Parse(response);

XNamespace fbns = XNamespace.Get("http://api.facebook.com/1.0/");
var friends = from el in xml.Root.Elements(fbns + "user")
	select new
		uid = el.Element(fbns + "uid").Value,
		name = el.Element(fbns + "name").Value