예제 #1
0
 public object this[string name, Type type]
 {
     get
     {
         Facebook.JsonObject asJsonObject = (Facebook.JsonObject)(CurrentNode.Current);
         if (asJsonObject.ContainsKey(name))
         {
             if (type == null)
             {
                 return(asJsonObject[name]);
             }
             return(ConvertPropertyFromJson(name, asJsonObject[name], type));
         }
         else
         {
             return(null);
         }
     }
 }
예제 #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;
            }
        }
        private Message CreateVideoMessage(JsonObject jsonData)
        {
            FacebookMessage msg = new FacebookMessage();

            string text = "<br />";

            if (jsonData.ContainsKey("message"))
            {
                text += HttpUtility.HtmlEncode((string)jsonData["message"]);
                text += "<br /><br />";
            }
            text += String.Format("<a href='{0}' target='_blank'><img src='{1}' /></a><br /><br />", jsonData["link"].ToString(), jsonData["picture"].ToString());

            msg.Text = text;
            msg.PostedOn = Convert.ToDateTime(jsonData["updated_time"].ToString());
            msg.Source = SocialNetworks.Facebook;

            JsonObject jsonUser = (JsonObject)(jsonData["from"]);
            msg.UserName = jsonUser["name"].ToString();
            msg.UserImageUrl = String.Format("http://graph.facebook.com/{0}/picture?type=small", jsonUser["id"]);

            return msg;
        }
예제 #4
0
        /// <summary>
        /// Parses the session value from a cookie.
        /// </summary>
        /// <param name="appSecret">
        /// The app Secret.
        /// </param>
        /// <param name="cookieValue">
        /// The session value.
        /// </param>
        /// <returns>
        /// The Facebook session object.
        /// </returns>
        internal static FacebookSession ParseCookieValue(string appSecret, string cookieValue)
        {
            Contract.Requires(!String.IsNullOrEmpty(appSecret));
            Contract.Requires(!String.IsNullOrEmpty(cookieValue));
            Contract.Requires(!cookieValue.Contains(","), "Session value must not contain a comma.");

            // var cookieValue = "\"access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026\"";
            // var result = FacebookSession.Parse("3b4a872617be2ae1932baa1d4d240272", cookieValue);

            // Parse the cookie
            var dictionary = new JsonObject();
            var parts = cookieValue.Replace("\"", string.Empty).Split('&');
            foreach (var part in parts)
            {
                if (!string.IsNullOrEmpty(part) && part.Contains("="))
                {
                    var nameValue = part.Split('=');
                    if (nameValue.Length == 2)
                    {
                        var s = FacebookUtils.UrlDecode(nameValue[1]);
                        dictionary.Add(nameValue[0], s);
                    }
                }
            }

            var signature = GenerateSessionSignature(appSecret, dictionary);
            if (dictionary.ContainsKey("sig") && dictionary["sig"].ToString() == signature)
            {
                return new FacebookSession(dictionary);
            }

            return null;
        }
예제 #5
0
        private object BuildExchangeCodeForAccessTokenResult(string json)
        {
            var returnParameter = new JsonObject();
            FacebookUtils.ParseQueryParametersToDictionary("?" + json, returnParameter);

            // access_token=string&expires=long or access_token=string
            // Convert to JsonObject to support dynamic and be consistent with the rest of the library.
            var jsonObject = new JsonObject();
            jsonObject["access_token"] = returnParameter["access_token"];

            // check if expires exist coz for offline_access it is not present.
            if (returnParameter.ContainsKey("expires"))
            {
                jsonObject.Add("expires", Convert.ToInt64(returnParameter["expires"]));
            }

            return jsonObject;
        }
예제 #6
0
 public string getfbappemail(JsonObject myInfo)
 {
     string stremail = "";
     if (myInfo.ContainsKey("email"))
     {
         stremail = myInfo["email"].ToString();
     }
     return stremail;
 }
예제 #7
0
파일: Story.cs 프로젝트: craigbrett17/Iris
 private object GetJsonValueIfExists(JsonObject jsonIn, string desiredKey)
 {
     if (jsonIn.ContainsKey(desiredKey))
     {
         return jsonIn[desiredKey];
     }
     return null;
 }