Starting multiquery in client throws parser error

2019-04-02 16:42发布

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?

2条回答
叼着烟拽天下
2楼-- · 2019-04-02 17:28

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!

查看更多
Deceive 欺骗
3楼-- · 2019-04-02 17:42

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);
查看更多
登录 后发表回答