开发者

Starting multiquery in client throws parser error

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/ref开发者_高级运维erence/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?


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);


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜