1

Prabir のブログのおかげで、facebook c# sdk v 6.14 を使用してマルチクエリ fql を正常に実行できますが、結果の解析に助けが必要です。私は無駄に多くの方法を検索して試しました。単純な構文の問題であることはわかっていますが、c# と JSON にはかなり慣れていません。

どんな助けでも大歓迎です!ありがとう、チャド

私のコード:

var fb = new FacebookClient(this.FacebookAccessToken);
            dynamic resultsMQFQL = fb.Get("fql",
                            new
                            {
                                q = new
                                {
                                    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, fan_count, categories, genre, starring, release_date FROM page WHERE page_id IN (SELECT page_id FROM #friendsMovies) ORDER BY fan_count DESC",
                                }
                            });

結果:

{"data":[
    {"name":"friendsMovies",
        "fql_result_set":
            [{"page_id":105638652803531,"uid":796419451},
            {"page_id":113271808686307,"uid":796419451}]},

    {"name":"movieDetails",
        "fql_result_set":[
            {"page_id":105638652803531,"name":"Fear and Loathing in Las Vegas"},
            {"page_id":113271808686307,"name":"Fletch"}
        ]
    }
]}

解析の試み:

foreach (dynamic row in resultsMQFQL.data.fql_result_set)

エラー:

'Facebook.JsonArray' does not contain a definition for 'fql_result_set' 
4

1 に答える 1

1

わかりました...すぐにウィンドウでデバッグしながらさまざまな組み合わせをすばやく試すことができることを忘れました...コーディングはかなり新しいと言いましたか?:)

public void FBMQFQL()
        {
            var fb = new FacebookClient(this.FacebookAccessToken);
            dynamic resultsMQFQL = fb.Get("fql",
                            new
                            {
                                q = new
                                {
                                    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, fan_count, categories, genre, starring, release_date FROM page WHERE page_id IN (SELECT page_id FROM #friendsMovies) ORDER BY fan_count DESC",
                                }
                            });

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

            var friendsMovies = resultsMQFQL.data[0].fql_result_set;
            var movieDetails = resultsMQFQL.data[1].fql_result_set;

            if (resultsMQFQL == null)
            {
                //return null;
            }
            else
            {
                //Construct the new, formated, merged datatable to store the results the way we want them   
                DataTable dtMyFriendsMovies = new DataTable();
                dtMyFriendsMovies.Columns.Add("MovieID");
                dtMyFriendsMovies.Columns.Add("FriendUserID");

                foreach (dynamic row in friendsMovies)
                {
                    //Add New DataRow to new DataTable
                    DataRow drRow = dtMyFriendsMovies.NewRow();

                    //Get various values from original JSON Friend List returned
                    drRow["MovieID"] = row.page_id;
                    drRow["FriendUserID"] = row.uid;

                    //Add New Row to New Resulting Data Table
                    dtMyFriendsMovies.Rows.Add(drRow);
                }

                //MovieDetails   
                DataTable dtMovies = new DataTable();

                dtMovies.Columns.Add("movieID");
                dtMovies.Columns.Add("name");
                dtMovies.Columns.Add("pic");
                dtMovies.Columns.Add("fan_count");
                dtMovies.Columns.Add("genre");
                dtMovies.Columns.Add("starring");
                dtMovies.Columns.Add("release_date");

                foreach (dynamic row in movieDetails)
                {
                    //Add New DataRow to new DataTable
                    DataRow drRow = dtMovies.NewRow();

                    //Get various values from original JSON Friend List returned
                    drRow["movieID"] = row.page_id;
                    drRow["name"] = row.name;
                    drRow["pic"] = row.pic;
                    drRow["fan_count"] = row.fan_count;
                    drRow["genre"] = row.genre;
                    drRow["starring"] = row.starring;
                    drRow["release_date"] = row.release_date;

                    //Add New Row to New Resulting Data Table
                    dtMovies.Rows.Add(drRow);
                }
                //return dtMyFriendsMovies;
            }
        } //FB FQL
于 2012-05-24T18:01:48.177 に答える