FQL.Multiquery - query syntax when passing as parameter

强颜欢笑 提交于 2019-12-11 18:41:26

问题


Looking for a little help with a simple task...the syntax for a facebook multi-query, where you'd pass in the query as a parameter.

Here is my method:

public dynamic FBFQL(string strQuery)
    {
        try
        {
            var fb = new FacebookClient(this.FacebookAccessToken);
            //dynamic objFQL = fb.Get("fql", new { q = strQuery });
            dynamic objFQL = fb.Get("fql", new { q = new { strQuery } });

            if (objFQL == null)
            {
                return null;
            }
            else
            {
                return objFQL;
            }
        }
        catch (FacebookApiException ex)
        {
            FacebookErrorHandler(ex);
            return null;
        }
    } //FB FQL

And my query syntax"

string strQuery = "friendsMovies = \"SELECT page_id, uid FROM page_fan WHERE type='MOVIE' AND uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY page_id\"," +
" movieDetails = \"SELECT page_id, name, pic, page_url, fan_count, genre, starring, release_date FROM page WHERE page_id IN (SELECT page_id FROM #friendsMovies) ORDER BY page_id\"";

But unfortunately, it gives the following error. I've tried it several ways to no avail. I'm sure it's something simple...I just can't see it at this point.

(OAuthException - #601) (#601) Parser error: unexpected 'friendsMovies' at position 0.

Thanks in advance Chad


回答1:


Figured it out and with named queries too:

The Calling method and processes the result:

public List<FacebookMovie> GetMoviesLikedByFriends()
    {
        string strQuery0 = "SELECT page_id, uid FROM page_fan WHERE type='MOVIE' AND uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY page_id";
        string strQuery1 = "SELECT page_id, name, pic, page_url, fan_count, genre, starring, release_date FROM page WHERE page_id IN (SELECT page_id FROM #friendsMovies) ORDER BY page_id";

        Dictionary<string, object> dicQuery = new Dictionary<string, object>();
        dicQuery.Add("friendsMovies", strQuery0);
        dicQuery.Add("movies", strQuery1);

        FacebookSDKInterface objFQL = new FacebookSDKInterface();
        dynamic objMoviesFriendsLike = objFQL.FBMFQL(dicQuery);

        //To access a direct value: resultsMQFQL.data[0].fql_result_set[0].page_id

        if (objMoviesFriendsLike != null) // shouldn't you check objFNU for being null here instead?
        {
            IEnumerable<dynamic> friendsMovies = (IEnumerable<dynamic>)objMoviesFriendsLike.data[0].fql_result_set; // explicit cast might not be necessary
            IEnumerable<dynamic> movieDetails = (IEnumerable<dynamic>)objMoviesFriendsLike.data[1].fql_result_set; // explicit cast might not be necessary

            IEnumerable<FacebookMovie> objMyFriendsMovies = 
                from Movie in movieDetails
                join FriendsMovies in friendsMovies on (string)Movie.page_id equals (string)FriendsMovies.page_id
                group FriendsMovies by new
                {
                    ID = Movie.movie_id,
                    Link = Movie.page_url,
                    MovieName = Movie.name,
                    TotalLikes = Movie.fan_count,
                    Genre = Movie.genre,
                    Starring = Movie.starring,
                    ReleaseDate = Movie.release_date,
                    PicURL = Movie.pic
                } into grp
                where grp.Count() >= 2 //at least 2 friends must have liked it to show up
                select new FacebookMovie()
                {
                    Source = "Facebook",
                    ID = (string)grp.Key.ID,
                    SourceURL = (string)grp.Key.Link,
                    Name = (string)grp.Key.MovieName,
                    Picture = (string)grp.Key.PicURL,
                    TotalLikes = (long)grp.Key.TotalLikes,
                    Genre = (string)grp.Key.Genre,
                    Starring = (string)grp.Key.Starring,
                    ReleaseDate = (string)grp.Key.ReleaseDate,
                    FriendLikes = (int)grp.Count()
                };

            objMyFriendsMovies = objMyFriendsMovies.OrderByDescending(p => p.FriendLikes);

            return objMyFriendsMovies.ToList();
        }
        else
        {
            return new List<FacebookMovie>();
        }
    }

The method to perform the query:

public dynamic FBMFQL(Dictionary<string, object> dicQuery)
    {
        try
        {
            var fb = new FacebookClient(this.FacebookAccessToken);
            dynamic objFQL = fb.Get("fql", new { q = dicQuery });

            if (objFQL == null)
            {
                return null;
            }
            else
            {
                return objFQL;
            }
        }
        catch (FacebookApiException ex)
        {
            FacebookErrorHandler(ex);
            return null;
        }
    } //FB FQL


来源:https://stackoverflow.com/questions/11681786/fql-multiquery-query-syntax-when-passing-as-parameter

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