0 Replies Latest reply on Jun 21, 2011 6:59 AM by fingersmagoo

    Code for Posting to a Facebook Wall

    fingersmagoo

      Hello I see this issue in the froums, so I thought would share my solution.

       

      Paul

       

      package

      {

      import com.facebook.graph.Facebook;

      import com.facebook.graph.FacebookMobile;

       

      import mx.binding.utils.BindingUtils;

      import mx.collections.*;

      import mx.managers.CursorManager;

       

      import spark.components.*;

       

      import views.FacebookWallPosterHomeView;

       

      public class BusinessLogic

      {

      private static var instance:BusinessLogic;

      public var appView:FacebookWallPosterHomeView;

      public var appID:String = "<YOUR_APP_ID>";

      private var permissions:Array = ['publish_stream','create_event','rsvp_event','sms','offline_access','email','read_insigh ts','read_stream','user_about_me',

      'user_activities','user_birthday','user_education_history','user_events','user_groups','us er_hometown',

      'user_interests','user_likes','user_location','user_notes','user_online_presence',

      'user_photo_video_tags','user_photos','user_relationships','user_religion_politics','user_ status',

      'user_videos','user_website','user_work_history','read_friendlists','read_requests','user_ notes'];

      public var loginId:int=0;

       

       

      public static function getInstance():BusinessLogic

      {

      if(instance == null) {

      instance = new BusinessLogic(new SingletonEnforcer());

      return instance;

      }

      else

      {

      return instance;

      }

      }

      public function BusinessLogic(enforcer:SingletonEnforcer){}

       

      public function login():void

      {

      FacebookMobile.login(loginHandler, appView.stage, permissions);

      }

      public function loginHandler(success:Object,fail:Object):void

      {

      CursorManager.setBusyCursor();

      if(success)

      {   

      trace(success.user.name);

      loginId=success.user.id;

      getItems();

      }

      else

      {

      login();

      }

      CursorManager.removeBusyCursor();

      }

      public function getItems():void

      {

      var query:String = "SELECT uid,status_id,message FROM status WHERE uid = me()";

      FacebookMobile.fqlQuery(query, getPostsReturn);

      }

      protected function getPostsReturn(success:Object,fail:Object):void

      {

      CursorManager.setBusyCursor();

      if(success)

      {

      appView.messages = new ArrayCollection();

      for (var j:int = 0; j < success.length; j++)

      {

      appView.messages.addItem(success[j]);

      trace(success[j].message);

      }

      }

      CursorManager.removeBusyCursor();

      }

       

      public function addWallPost():void

      {

      CursorManager.setBusyCursor();

      var data:Array = new Array();

      data["message"] = appView.txtMessage.text;

      FacebookMobile.postData("/feed", postCallback, data);

      }

      protected function postCallback(success:Object,fail:Object):void

      {

      var data:Array = new Array();

      data["message"] = appView.txtMessage.text;

      data["status_id"] = success.id;

      data["uid"] = loginId;

       

      appView.messages.addItemAt(data, 0);

      appView.txtMessage.text="";

      CursorManager.removeBusyCursor();

      }

       

      public function removeItem(o:Object):void

      {

      var data:Array = new Array();

      data["id"] = loginId+"_"+o.uid;

      data["method"] = "delete";

      //FacebookMobile.deleteObject(loginId+"_"+o.uid, deleteCallback);

      FacebookMobile.postData("/delete", deleteCallback, data);

      }

      protected function deleteCallback(success:Object,fail:Object):void

      {

      appView.messages.removeItemAt(appView.lstMessages.selectedItem);

      CursorManager.removeBusyCursor();

      }

      public function setAppView(myView:FacebookWallPosterHomeView):void

      {

      appView=myView;

      }

      protected function logout():void

      {

      FacebookMobile.logout();

      }

      }

      }

      class SingletonEnforcer {}