2011年10月24日 星期一

Facebook WinForm API (2)

1. There are three forms in this example:
1.1 Mainform (start program)
1.2 Browser in a form (login)
1.3 WinForm (Employ api communicate with Facebook server)
2. Test FqlAsyncSample() @  WinForm class
There are serveral testing methods in the constructor
            _accessToken = accessToken;
            InitializeComponent();
            GraphApiAsyncExample();
            LegacyRestApiAsyncExample();
            FqlAsyncSample();
            FqlMultiQueryAsyncSample();
            GraphApiBatchRequestAsyncSample();
            GraphApiExample();
3.  FqlAsyncSample();
 private void FqlAsyncSample()
        {
            var fb = new FacebookClient(_accessToken);
// 非同步語法             fb.QueryAsync(query); @ 最後一行,完成後執行此事件
            fb.GetCompleted +=
                (o, e) =>
                {
                    if (e.Error == null)
                    {
                        var result = (IList<object>)e.GetResultData();
                        var count = result.Count;
                        lblTotalFriends.Text = string.Format("You have {0} friend(s).", count);
                        foreach (dynamic friend in result)
                        {
// friend.屬性 由 SELECT 欄位名稱決定
                            textBox1.Text +=   friend.last_name + friend.first_name +  ": Facebook username: " + friend.username + "\n\n";
                        }
   
                    }
                    else
                    {
                        MessageBox.Show(e.Error.Message);
                    }
                };
            // query to get all the friends
            var query = string.Format("SELECT uid,pic_square, name, last_name, first_name  FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0})", "me()");
            fb.QueryAsync(query);
        }
4. 圖片 pic_square 為url
friend.pic_square
http://profile.ak.fbcdn.net/hprofile-ak-snc4/491XX_560998701_3563_q.jpg

沒有留言:

張貼留言