Exemplo n.º 1
0
        private void ProcessFacebookData(string path, Func <JSONObject, List <Task> > task)
        {
            List <Task> tasks = new List <Task>();
            var         api   = new FacebookAPI(Token);
            var         args  = new Dictionary <string, string>();

            args.Add("limit", "100");
            var results = api.Get(path, args);
            var next    = (results.Dictionary.ContainsKey("paging")) &&
                          results.Dictionary["paging"].Dictionary.ContainsKey("next")
                ? results.Dictionary["paging"].Dictionary["next"].String : null;

            do
            {
                tasks.AddRange(task(results.Dictionary["data"]));

                if (!string.IsNullOrEmpty(next))
                {
                    args = new Dictionary <string, string>();
                    args.Add("until", next.Split(new string[] { "until=" }, StringSplitOptions.RemoveEmptyEntries)[1]);
                    args.Add("limit", "100");
                    results = api.Get(path, args);
                    if (results.Dictionary.ContainsKey("paging"))
                    {
                        if (next != results.Dictionary["paging"].Dictionary["next"].String)
                        {
                            next = results.Dictionary["paging"].Dictionary["next"].String;
                        }
                        else
                        {
                            next = null; results = null;
                        }
                    }
                    else
                    {
                        next = null; results = null;
                    }
                }
                else
                {
                    results = null;
                }
            }while (results != null);
            Task.WaitAll(tasks.ToArray());
        }
Exemplo n.º 2
0
 public String GetMyName()
 {
     try
     {
         JSONObject me = myFBAPI.Get("/me");
         return(me.Dictionary["name"].String);
     }
     catch (FacebookAPIException err)
     {
         return(err.Message);
     }
 }
Exemplo n.º 3
0
        public SocialNetworkingSearchResult Search(string searchParameters, int page)
        {
            List <SocialNetworkingItem> list;

            try
            {
                var        api       = new FacebookAPI();
                var        engineURL = GetEngineUrl();
                JSONObject json      = api.Get(engineURL + searchParameters + "&type=post&limit=100");

                list = SocialNetworkingItemList(json);
                return(new SocialNetworkingSearchResult()
                {
                    SocialNetworkingItems = list, SocialNetworkingName = Name
                });
            }
            catch (Exception e)
            {
                Logger.Log.Error(e);
            }
            return(null);
        }
        /// <summary>
        /// Gets facebook feeds from Facebook API version 1.1
        /// </summary>
        /// <param name="id">facebook user id</param>
        /// <param name="limit">facebook feed count</param>
        /// <param name="feed"></param>
        /// <returns></returns>
        public ActionResult GetFacebookJson(string id, string limit, string feed)
        {
            var userId     = id.Split('|')[0];
            var accessCode = id.Split('|')[1];
            var api        = new FacebookAPI(accessCode);
            // Facebook attributes used as a query string includes in facebook API
            var attributes = new Dictionary <string, string>
            {
                { "limit", limit },
                { "fields", FaceBookFeedParams }
            };
            // Get all facebook feeds from API
            var facebookFeeds = api.Get("/" + FaceBookAPIVersion + "/" + userId + "/" + feed, attributes);
            List <FacebookFeedItem> socialFeeds = new List <FacebookFeedItem>();

            if (facebookFeeds.Dictionary["data"] != null && facebookFeeds.Dictionary["data"].Array.Length > 0)
            {
                JSONObject[] jsonArray = facebookFeeds.Dictionary["data"].Array;
                foreach (JSONObject jsonObj in jsonArray)
                {
                    if (jsonObj != null)
                    {
                        // Create new instance of facebook feed class
                        var socialFeed = new FacebookFeedItem();
                        // Fill facebook feed name
                        if (jsonObj.Dictionary.ContainsKey("from") && jsonObj.Dictionary["from"].Dictionary.ContainsKey("name"))
                        {
                            socialFeed.Title = jsonObj.Dictionary["from"].Dictionary["name"].String;
                        }

                        // Fill facebook feed picture
                        if (jsonObj.Dictionary.ContainsKey("from") && jsonObj.Dictionary["from"].Dictionary.ContainsKey("picture"))
                        {
                            socialFeed.Thumb = new Image()
                            {
                                Src = jsonObj.Dictionary["from"].Dictionary["picture"].Dictionary["data"].Dictionary["url"].String,
                                Alt = "Thumbnail"
                            };
                        }

                        // Fill facebook feed full picture
                        if (jsonObj.Dictionary.ContainsKey("full_picture") && !jsonObj.Dictionary["full_picture"].String.IsNullOrEmpty())
                        {
                            socialFeed.FullPicture = new Image()
                            {
                                Src = jsonObj.Dictionary["full_picture"].String,
                                Alt = "Image"
                            };
                        }

                        // Fill facebook feed link
                        if (jsonObj.Dictionary.ContainsKey("from") && jsonObj.Dictionary["from"].Dictionary.ContainsKey("link"))
                        {
                            socialFeed.Link = new Link()
                            {
                                Url = jsonObj.Dictionary["from"].Dictionary["link"].String
                            };
                        }

                        // Fill facebook feed message
                        if (jsonObj.Dictionary.ContainsKey("message") && !jsonObj.Dictionary["message"].String.IsNullOrEmpty())
                        {
                            socialFeed.Content = Regex.Replace(jsonObj.Dictionary["message"].String, @"\r\n?|\n", "<br />");
                        }
                        // Fill facebook feed last updated time
                        if (jsonObj.Dictionary.ContainsKey("updated_time") && !jsonObj.Dictionary["updated_time"].String.IsNullOrEmpty())
                        {
                            var dateTime = DateTime.Parse(jsonObj.Dictionary["updated_time"].String).ToString("MMMM dd,yyyy, hh:mm tt");
                            socialFeed.DateLocation = dateTime;
                            socialFeed.Date         = dateTime;
                        }

                        // Fill facebook feed place
                        if (jsonObj.Dictionary.ContainsKey("place") && jsonObj.Dictionary["place"].Dictionary.ContainsKey("location"))
                        {
                            var place = jsonObj.Dictionary["place"].Dictionary["location"].Dictionary["city"].String + ", " + jsonObj.Dictionary["place"].Dictionary["location"].Dictionary["country"].String;
                            socialFeed.DateLocation = socialFeed.DateLocation + " near " + place;
                        }
                        // Add new instance of facebook feed in facebook feeds
                        socialFeeds.Add(socialFeed);
                    }
                }
            }
            // Serialize social feeds instance into json string
            return(this.Json(socialFeeds, JsonRequestBehavior.AllowGet));
        }