ToString() public method

Prints the JSONObject as a formatted string, suitable for viewing.
public ToString ( ) : string
return string
        private static void LoginNavigationStarted(Uri url, object state)
        {
            FacebookOAuthResult result;
            // Check if we're waiting for user input or if login is complete
            if (_client.TryParseOAuthCallbackUrl(url, out result))
            {
                // Login complete
                if (result.IsSuccess)
                {
                    AccessToken = result.AccessToken;
                    Expires = result.Expires;
                    _client.AccessToken = AccessToken;
                    Settings.Set(TOKEN_KEY, EncryptionProvider.Encrypt(AccessToken, AppId));
                    Settings.Set(EXPIRY_DATE_BIN, Expires.ToBinary());
                }
                _web.Finish();
                if (_onHideUnity != null)
                {
                    _onHideUnity(false);
                }

                API("/me?fields=id,name", HttpMethod.GET, fbResult =>
                {
                    if (IsLoggedIn)
                    {
                        UserId = fbResult.Json["id"] as string;
                        UserName = fbResult.Json["name"] as string;
                        Settings.Set(FBID_KEY, UserId);
                        Settings.Set(FBNAME_KEY, UserName);
                    }

                    if (state is FacebookDelegate)
                    {
                        JsonObject jResult = new JsonObject();
                        jResult.Add(new KeyValuePair<string, object>("authToken", AccessToken));
                        jResult.Add(new KeyValuePair<string, object>("authTokenExpiry", Expires.ToString()));

                        ((FacebookDelegate)state)(new FBResult()
                        {
                            Json = jResult,
                            Text = jResult.ToString()
                        });
                    }
                });
            }
        }
Ejemplo n.º 2
0
        private object ProcessResponse(HttpHelper httpHelper, string responseString, Type resultType, bool containsEtag, IList<int> batchEtags)
        {
            try
            {
                object result = null;

                if (httpHelper == null)
                {
                    // batch row
                    result = DeserializeJson(responseString, resultType);
                }
                else
                {
                    var response = httpHelper.HttpWebResponse;

                    if (response == null)
                        throw new InvalidOperationException(UnknownResponse);

                    if (response.ContentType.Contains("text/javascript") ||
                        response.ContentType.Contains("application/json"))
                    {
                        result = DeserializeJson(responseString, resultType);
                    }
                    else if (response.StatusCode == HttpStatusCode.OK && response.ContentType.Contains("text/plain"))
                    {
                        if (response.ResponseUri.AbsolutePath == "/oauth/access_token")
                        {
                            var body = new JsonObject();
                            foreach (var kvp in responseString.Split('&'))
                            {
                                var split = kvp.Split('=');
                                if (split.Length == 2)
                                    body[split[0]] = split[1];
                            }

                            if (body.ContainsKey("expires"))
                                body["expires"] = Convert.ToInt64(body["expires"]);

                            result = resultType == null ? body : DeserializeJson(body.ToString(), resultType);

                            return result;
                        }
                        else
                        {
                            throw new InvalidOperationException(UnknownResponse);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException(UnknownResponse);
                    }
                }

                var exception = GetException(httpHelper, result);
                if (exception == null)
                {
                    if (containsEtag && httpHelper != null)
                    {
                        var json = new JsonObject();
                        var response = httpHelper.HttpWebResponse;

                        var headers = new JsonObject();
                        foreach (var headerName in response.Headers.AllKeys)
                            headers[headerName] = response.Headers[headerName];

                        json["headers"] = headers;
                        json["body"] = result;

                        return json;
                    }

                    return batchEtags == null ? result : ProcessBatchResponse(result, batchEtags);
                }

                throw exception;
            }
            catch (FacebookApiException)
            {
                throw;
            }
            catch (Exception)
            {
                if (httpHelper != null && httpHelper.InnerException != null)
                    throw httpHelper.InnerException;

                throw;
            }
        }
Ejemplo n.º 3
0
        private async void GetUserData(Dictionary <string, string> param)
        {
            if (busy)
            {
                sendBusyEvent();
            }

            busy = true;

            try
            {
                string  path       = "/me";
                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>("path"))
                {
                    path = param["path"];
                }

                Facebook.JsonObject result = await _fb.GetTaskAsync(path, parameters);

                string js = "javascript: var e = document.createEvent('Events');e.initEvent('appMobi.facebook.request.response',true,true);e.success=true;e.raw='" + result.ToString() + "';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.E000203);
                    //string js = "(function(){ AppMobi.facebook.internal.handleResponse('request.response',false," + sr.ToJson() + ")})();";
                    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
                {
                    // user not logged in.
                    ScriptResponse sr = ErrorHandler.setupErrorResponse(ErrorsEnum.E000202);
                    //string js = "(function(){ AppMobi.facebook.internal.handleResponse('request.response',false," + sr.ToJson() + ")})();";
                    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; }
        }