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

それを理解し、名前付きクエリも使用しました:

Callingメソッドと結果を処理します。

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 に答える