Starting multiquery in client throws parser error

做~自己de王妃 提交于 2019-12-21 06:56:04

问题


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?


回答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!




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


来源:https://stackoverflow.com/questions/5144488/starting-multiquery-in-client-throws-parser-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!