Display FQL results in DataGridView using C# (WinForms)

99封情书 提交于 2019-12-02 02:01:01
Vland

C# Winforms solution using a DataGridView control like you specify in the title.


1) Modify your MyFriend class, I changed it a little bit

public class MyFriends
{
    public long uid { get; set; }            
    public string username { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public long? friend_count { get; set; }  //nullable
    public string pic_big { get; set; }
}

2) Add DataGridView control to your form

3) Deserialize your result.data using JsonConvert to a List. You should also pass result.data.ToString() or it will give an exception.

4) Bind your new list to DataGridView.Datasource

var fb = new FacebookClient("accessToken");

var query = string.Format(@"SELECT uid, username, first_name, last_name, friend_count, pic_big 
                            FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");

dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = fb.Get("/fql", parameters);

List<MyFriends> q = JsonConvert.DeserializeObject<List<MyFriends>>(results.data.ToString());

dataGridView1.DataSource = q;

Result:

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