1

I have a following problem in c# SDK: when I try to run multiquery in my desktop application with following string (searching for pairs of IDs of mutual friends) I get a parser error:

string strCommonFriendsQuery = "{
        \"user_friends\":\"SELECT uid2 FROM friend WHERE uid1 = me()\", 
        \"mutual_friends\":\"SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM   #user_friends) AND uid2 IN (SELECT uid2 FROM #user_friends)\"
        }";

        fb.Query(strCommonFriendsQuery);

Parser error: unexpected '{' at position 0.

The same string (without the escape sequences before quotation marks) works if I paste it to http://developers.facebook.com/docs/reference/rest/fql.multiquery/ but not in http://developers.facebook.com/docs/reference/rest/fql.query/ so the problem is that I need to launch it as multiquery and not as a query - now what I would like to ask is:

Is it possible to somehow process multi-query using the Facebook.FacebookClient.Query function of the SDK or do I have to write a function which would do that? As I understand the only thing I would need to change is the address to which it connects to. If so, could it be added in the next SDK version?

Euqil
  • 391
  • 1
  • 10
  • I feel really stupid not finding out that the function has two prototypes where the other one takes an array of strings for multiquery. – Euqil Mar 01 '11 at 08:30

2 Answers2

2

Here is an alternate to firepol's answer, with named queries:

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);
N8allan
  • 2,138
  • 19
  • 32
1

To do a multiquery with a reference to the first query, such as the one in the question, do as follows:

//note: queries begin from 0, not from 1
string query0 = "SELECT uid2 FROM friend WHERE uid1 = me()";
string query1 = "SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM #query0) AND uid2 IN (SELECT uid2 FROM #query0)";

dynamic result = fb.Query(query0, query1);

To answer this, I got inspired from here (had to figure out that queries start from 0): How to use fql.multiquery with C# SDK

Enjoy!

Community
  • 1
  • 1
firepol
  • 1,731
  • 22
  • 39
  • Thanks for this, I'm glad to see a solution. However, this seems a bit too magical for my tastes. How did the variable names end up being conveyed as query names? IOW, what is the non-dynamic version of this? To reflector... – N8allan May 13 '11 at 05:12
  • Ahh, query is simply the auto-naming convention used in Query(). Items are added from the provided list as such: dictionary.Add("query" + i, fql[i]); The result is passed to Get(). – N8allan May 13 '11 at 05:22
  • Yeah, I named the strings "query0" and "query1" to avoid confusion. I could have named them also "foo" and "bar" if I wanted, but still they would be called "query0" and "query1" without specifying their name as you did in your following answer. – firepol May 13 '11 at 09:26