2011年10月26日 星期三

FB1 發佈到塗鴉牆

***首先要import的就是facebook class

 import com.facebook.graph.Facebook;

***輸入你的app id
  
  protected static const APP_ID:String = "2011045***62438"; //APP的ID
  
***初始化並在按鈕上加事件
  
  protected function configUI():void {
   Facebook.init(APP_ID,initHandler);
   publish_btn.addEventListener(MouseEvent.CLICK, handlePublishClick, false, 0, true);
  }
***判斷有無登入
  
public function initHandler(result:Object, fail:Object):void
  {
   trace("init2");
   if (result)
   {
    //txt_mc.txt.text = "asdf";
    trace("result.uid = " +result.uid);
   //若曾經登入過,這邊就可以取得session,可以執行自動登入的動作
   }else {
    //txt_mc.txt.text = "false3";
    
    trace("false")
   }
  }
發佈至塗鴉牆
private function handlePublishClick(e:MouseEvent):void 
{
   var data:Object = new Object();
   data.link = "http://developers.facebook.com/docs/reference/dialogs/";
   data.picture="http://fbrell.com/f8.jpg"
   data.name = "這是asdfasdfasdfname";
   data.caption = "這是cadsfasdfasdaption";
   data.description = "這是dsdfasdfasdfescription";
   data.message = "這是mesdsfsfsdfasdfsage";
   data.source = "http://**************************;
   
   var picdata:Object = new Object();
   picdata.name = "下載圖片";
   picdata.link = "http://fbrell.com/f8.jpg";
   
   data.actions = picdata;
   
   trace("發佈至塗鴉牆" + data);
   Facebook.ui("feed", data, requestHandler, "popup");
  }
  
  private function requestHandler(result:Object, fail:Object = null):void 
  {
   trace(result + "" + fail);
  }
   
 }
}

沒有留言:

張貼留言