How to do named multiqueries using C# Facebook SDK
-
06-03-2021 - |
Question
I'm updating some legacy code from the old 3.0 version of the C# Facebook SDK to the new 5.3.2 version.
On http://developers.facebook.com/docs/reference/fql/ it shows that you can do a multiquery like:
"query1":"SELECT uid, rsvp_status FROM event_member WHERE eid=12345678"
"query2":"SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"
In the old API, you'd just have a Dictionary where each query was paired up with it's name:
"page_admin_list","SELECT uid, page_id, type FROM page_admin where uid = 1234567890"
"permissions_response","SELECT uid, read_stream, status_update, photo_upload, publish_stream, offline_access FROM permissions WHERE uid IN (SELECT page_id FROM #page_admin_list)"
In each of the examples, notice the # in the nested query. However, I'm unsure how to accomplish this with the new syntax since it is only accepting string[] as the parameter.
Solution
Starting from Facebook C# SDK v6 you can execute named queries using the following method.
var fb = new FacebookClient("access_token");
dynamic result = fb.Get("fql",
new
{
q = new
{
id = "SELECT uid from user where uid=me()",
name = "SELECT name FROM user WHERE uid IN (SELECT uid FROM #id)",
}
});
OTHER TIPS
Found this answer (edit: this applies to the earlier versions of the sdk, for version 6 and above see prabir's answer) : I have to reference each query by #query0, #query1, etc...
Or I can use the Get() method rather than the Query() method
var queries =
new Dictionary<string, object>
{
{ "FamDamly", "select uid from family where profile_id = me()" },
{ "FamDetails", "select uid, first_name from user where uid in #FamDamly" }
};
client.Get(queries);