2011年10月24日 星期一

Facebook WinForm API (4)

批次處理圖片下載
1. 結合API(2) API(3) 功能,將好友大頭貼批次下載如下:
Image im = null;
                        foreach (dynamic friend in result)
                        {
                            textBox1.Text +=   friend.last_name + friend.first_name +  ": Facebook username: " + friend.username + "\n\n";
                           
                            im = DownloadImageClass.DownloadImage(string.Format(friend.pic_square));
                            im.Save(friend.name + ".jpg");
                        }
2. Test OK!

Facebook WinForm API (3)

測試下載圖片 GraphApiAsyncExample();
1. Ref: http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Download-Image-from-URL.html
1.1 下載網頁圖片
2  用Ref1建立 Class DownloadImageClass, 製作DownloadImage類別方法。
3. 修改  GraphApiAsyncExample()
var fb = new FacebookClient(_accessToken);
            try
            {
                dynamic result = fb.Get("/me");
                var name = result.name;
                lnkName.Text = "Hi " + name;
                lnkName.LinkClicked += (o, e) => Process.Start(result.link);
                // available picture types: square (50x50), small (50xvariable height), large (about 200x variable height) (all size in pixels)
                // for more info visit http://developers.facebook.com/docs/reference/api
                picProfilePic.LoadAsync(string.Format("https://graph.facebook.com/{0}/picture?type={1}", result.id, "square"));
// ----------- 建置image 物件
// ----------- 下載網址圖片
// ----------- 另存圖檔 Test1.jpg
                Image im = null;
                im = DownloadImageClass.DownloadImage(string.Format("https://graph.facebook.com/{0}/picture?type={1}", result.id, "square"));
                im.Save("Test1.jpg");
4. 測試OK!

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

2011年10月22日 星期六

圖形比對(Image matching)

1. Ref: http://briian.com/?p=7224
TinEye 可以用來作為圖形比對。
2. Ref: http://www.tineye.com/search/209759428e73f8572d44b91b861a40f4df7113b9/
提供線上比對tineye資料圖庫
example

3. 似乎有API可以運用。