public static ScriptResponse setupErrorResponse(string responseCode, string message, string token = "")
 {
     ScriptResponse sr = new ScriptResponse();
     sr.ResponseCode = responseCode;
     sr.Message = message;
     sr.token = token;
     return sr;
 }
        public static ScriptResponse setupErrorResponse(string responseCode, string message, string token = "")
        {
            ScriptResponse sr = new ScriptResponse();

            sr.ResponseCode = responseCode;
            sr.Message      = message;
            sr.token        = token;
            return(sr);
        }
        private async void PostUserData(Dictionary<string, string> param)
        {
            if (busy)
                sendBusyEvent();

            busy = true;

            try
            {
                string path = "/me/feed";

                dynamic parameters = new ExpandoObject();
                if (param.Keys.Contains<string>("name")) { parameters.name = param["name"]; }
                if (param.Keys.Contains<string>("caption")) { parameters.caption = param["caption"]; }
                if (param.Keys.Contains<string>("link")) { parameters.link = param["link"]; }
                if (param.Keys.Contains<string>("picture")) { parameters.picture = param["picture"]; }
                if (param.Keys.Contains<string>("message")) { parameters.message = param["message"]; }
                if (param.Keys.Contains<string>("path")) { path = param["path"]; }

                dynamic result = await _fb.PostTaskAsync(path, parameters);
                _lastMessageId = result.id;
                
                ScriptResponse sr = new ScriptResponse { Message = "Facebook Post Successful", ResponseCode = "" };
                //string js = "(function(){ AppMobi.facebook.internal.handleResponse('dialog.complete',true," + sr.ToJson() + ")})();";
                string js = "javascript: var e = document.createEvent('Events');e.initEvent('appMobi.facebook.request.response',true,true);e.success=true;e.raw='" + sr.ToJson() + "';e.data={};try{e.data=JSON.parse(e.raw);}catch(ex){}e.error='';document.dispatchEvent(e);";
                InjectJS(js);
            }
            catch (FacebookApiException ex)
            {
                // handle error message
                if (ex.ErrorCode == 2500)
                {
                    // user not logged in.
                    ScriptResponse sr = ErrorHandler.setupErrorResponse(ErrorsEnum.E000201);
                    string js = string.Format("javascript: var e = document.createEvent('Events');e.initEvent('appMobi.facebook.request.response',true,true);e.success=false;e.error='{0}';e.raw='';e.data={{}};document.dispatchEvent(e);", sr.Message);
                    InjectJS(js);
                }
                else
                {
                    ScriptResponse sr = ErrorHandler.setupErrorResponse(ErrorsEnum.E000200);
                    //ScriptResponse sr = new ScriptResponse { Message = "Facebook Post Failed", ResponseCode = "" };
                    string js = string.Format("javascript: var e = document.createEvent('Events');e.initEvent('appMobi.facebook.request.response',true,true);e.success=false;e.error='{0}';e.raw='';e.data={{}};document.dispatchEvent(e);", sr.Message);
                    InjectJS(js);
                }
            }
            finally
            { busy = false; }
        }