2009年12月30日 星期三

建立Facebook應用程式 Java API (5) - 取得朋友Profile內的資料

//設定要取得的欄位
 Set fields = new HashSet();
 fields.add(ProfileField.SEX.fieldName()); //性別
 fields.add(ProfileField.NAME.fieldName()); //姓名
 fields.add(ProfileField.BIRTHDAY.fieldName()); //生日
 fields.add(ProfileField.PIC_SMALL.fieldName()); //大頭照

 //取得所有朋友的Uid
 List friendsUid = client.friends_get().getUid();

 //取得使用者資訊
 List users = client.users_getInfo(friendsUid, fields).getUser();
 for(User user:users) {
     user.getSex(); //男:male 女:female
     user.getName();
     user.getBirthday();
     user.getPicSmall(); //大頭照圖片網址
 } 


2009年12月22日 星期二

建立Facebook應用程式 Java API (4) - 發佈通知及張貼訊息到塗鴨牆

利用Facebook API可以發佈通知給使用者的朋友,也可以貼訊息到使用者的塗鴨牆上。

1. 發佈通知給使用者的朋友
List reciver = new ArrayList();
reciver.add(friendsUID);
client.notifications_send(reciver, "msg"); 

2.  貼訊息到使用者的塗鴨牆上
// 貼訊息到使用者的塗鴨牆上(每個使用者一日限十篇)
// 設定張貼的訊息
Attachment attachment = new Attachment();
attachment.setName("Name");
//設定Name的超連結位址
attachment.setHref("http://www.google.com.tw/");
attachment.setCaption("caption");
attachment.setDescription("yahoo description\ntest");

//加入圖片
AttachmentMediaImage attachmentMediaImage = new AttachmentMediaImage("http://www.google.com.tw/intl/en_com/images/logo_plain.png", "http://www.google.com");
attachment.setMedia(attachmentMediaImage);

//ActionLink是會出現在'留言 · 讚'後面的超連結(只有發佈到自己的塗鴨牆才會出現)
List actionLiks = new ArrayList();
BundleActionLink bundleActionLink = new BundleActionLink("yahoo", "http://tw.yahoo.com");
actionLiks.add(bundleActionLink);

//發佈到塗鴨牆
client.stream_publish("This is a Java API Test.", attachment, actionLiks, null, null);


2009年12月20日 星期日

建立Facebook應用程式 Java API (3) - 利用API取得使用者相關資訊

透過Facebook API可以取得使用者Profile內的資料(除了Email)、使用者所有朋友的Profile資料(如:名子、性別、圖片…)以及和應用程式相關的資料。

String sessionKey = request.getParameter("fb_sig_session_key");
 FacebookJaxbRestClient client = new FacebookJaxbRestClient(apiKey, secret, sessionKey);

  //使用者UID
  Long userId = client.users_getLoggedInUser();

 //使用者的所有friends
  List friendsUID = client.friends_get().getUid();

  //使用者friend的分類
  List friendLists = client.friends_getLists().getFriendlist();

  //有使用此應用程式的friends
  List appUsers = client.friends_getAppUsers().getUid();

  //檢查應用程式是否有發佈訊息到使用者塗鴨牆的權限(也可利用此方法來檢查其它權限)
  boolean publish  = client.users_hasAppPermission(Permission.PUBLISH_STREAM);

  //使用者授權的連結
  String url = Permission.authorizationUrl(apiKey, Permission.PUBLISH_STREAM); 


2009年12月15日 星期二

建立Facebook應用程式 Java API (2) - 開始使用Java API

1. 下載Java API

2. 將所需的Jar檔匯入

3. 建立一個Servlet(此Servlet的位址需是Canvas Callback URL)

4. 撰寫此Servlet
     a. 藉由fb_sig_session_key參數來判斷該FB使用者是否有加入此應用程式
            String sessionKey = request.getParameter("fb_sig_session_key");
     b. 若sessionKey為null則表示該FB使用者未加入此應用程式,則將網頁重新導向到要求允許存取頁面
           <script type='text/javascript'>
                parent.location.href='http://www.facebook.com/login.php?v=1.0&api_key=[your_api_key]&
               next=[Canvas Callback URL]&canvas=';
            </script>
     c. 若sessionKey不為null,則可使用api_key, secret, seessionKey來取得FacebookJaxbRestClient
             FacebookJaxbRestClient client = new FacebookJaxbRestClient(api_key, secret, seessionKey);


2009年12月13日 星期日

建立Facebook應用程式 Java API (1) - 申請應用程式

1. 加入開發人員應用程式
 
2. 建立一個新的應用程式

3.  輸入應用程式名稱

4.  記住自己應用程式的ID, API key, Secret

5. 選擇畫布(Canvas),並輸入你的Canvas url(需小寫)及你的server的url

6.  應用程式的細節




2009年12月2日 星期三

Android學習筆記 - 安裝Netbeans 6.7 Android Plugin

1. 選擇Tools -> Plugins

2. 選擇Setting並按下新增

3. 輸入Plugin的URL http://kenai.com/downloads/nbandroid/updates.xml

4.  到Avalible Plugins找到Android並安裝

5. 安裝完成後,新增一個Android的專案

6.  選擇Manage Platforms

7. 新增一個Android Platform


8. 選擇Android SDK的安裝位置


 9.選擇要使用的Target
 





2009年12月1日 星期二

Imperatives and infinitives for giving suggestions

  • Be sure (not) to
  • Don't forget (not) to
  • Make sure (not) to
  • Remember (not) to
  • Try (not) to