0

为一个简单的任务寻找一点帮助...... facebook 多查询的语法,您可以在其中将查询作为参数传递。

这是我的方法:

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

还有我的查询语法”

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\"";

但不幸的是,它给出了以下错误。我试了好几种方法都无济于事。我确定这很简单......我现在看不到它。

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

在此先感谢乍得

4

1 回答 1

0

想通了,也有命名查询:

调用方法并处理结果:

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

执行查询的方法:

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
于 2012-07-27T16:50:07.653 回答