public async Task <ActionResult> Posts()
        {
            //Access Token
            var currentClaims = await UserManager.GetClaimsAsync(HttpContext.User.Identity.GetUserId());

            var accesstoken = currentClaims.FirstOrDefault(x => x.Type == "urn:tokens:facebook");

            if (accesstoken == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Token not found"));
            }

            //format a url  to retrieve posts or feed data from facebook
            string url = string.Format(
                "https://graph.facebook.com/me?fields=id,name,feed.limit(1000){{attachments,message,story,created_time}}&access_token=EAAD48iRvOb4BAJ2aEOdAqlmCZAWRPOmSZB7LdOH5x1ZB4xmVHx0u9ckEoS9EQAlzjGhtO2RyB4fEpyYZCX3PABPUP6sQaZC4cIqXmyXhkWGkIk9xTKYJzHZAv78pFSNeO4ydjGP7wA218rYwE9gIiRkfHNIWA6aEpEOYkBvN7GXYhjV5g1XpS4nlOZB9mo0vdgq0ihVOI5Gr6ZBaZC5b1nvj3eJOJRHBdqcDzmRhvqCWQUgZDZD", accesstoken.Value);

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";

            using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string result = await reader.ReadToEndAsync();

                dynamic jsonobj = System.Web.Helpers.Json.Decode(result);

                Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonobj);

                ViewBag.JSON = result;
                return(View(posts));
            }
        }
Exemple #2
0
        public async Task <ActionResult> Posts()
        {
            var currentClaims = await UserManager.GetClaimsAsync(HttpContext.User.Identity.GetUserId());

            var accesstoken = currentClaims.FirstOrDefault(x => x.Type == "urn:tokens:facebook");

            if (accesstoken == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Toekn not found"));
            }

            string url = String.Format("https://graph.facebook.com/me?fields=id,name,feed.limit(100){{message,story,created_time,attachments{{description,type,url,title,media,target}},likes{{id,name}},comments{{id,from,message}}}}&access_token={0}", accesstoken.Value);

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";

            using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string result = await reader.ReadToEndAsync();

                dynamic jsonObj = System.Web.Helpers.Json.Decode(result);
                Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonObj);

                ViewBag.JSON = result;
                return(View(posts));
            }
        }
        public async Task <ActionResult> Posts()
        {
            //Access Token
            var currentClaims = await UserManager.GetClaimsAsync(HttpContext.User.Identity.GetUserId());

            var accesstoken = currentClaims.FirstOrDefault(x => x.Type == "urn:tokens:facebook");

            if (accesstoken == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Token not found"));
            }

            //format a url  to retrieve posts or feed data from facebook
            string url = string.Format(
                "https://graph.facebook.com/me?fields=id,name,feed.limit(1000){{attachments,message,story,created_time}}&access_token=EAAYZBjZBHfshEBAKUMJkiZBSeGirVKLlJ8w59N8dbmUHCvd9UXe2B9RGoeDudmrISqQEzAwtvYbRQIrOnmewZAtYXQbvG4qAglPFyylYmZBeSn8lzS8j9z6O7EiUuahbvOhoScs6OEEN1IgZBbFB7xdmvvpdxD83I6GmLoi7WRHuNXeaODZAEb9bEpBsyTRi9vY7AiuJiBwfpnYNfd5ZBFvJLt6cvXIkOWyB5ZCDIly8KOQZDZD", accesstoken.Value);

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";

            using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string result = await reader.ReadToEndAsync();

                dynamic jsonobj = System.Web.Helpers.Json.Decode(result);

                Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonobj);

                ViewBag.JSON = result;
                return(View(posts));
            }
        }
        public async Task <ActionResult> Posts()
        {
            Models.SocialMedia.Facebook.FacebookClient facebookClient = new Models.SocialMedia.Facebook.FacebookClient();
            facebookClient.HttpContext = HttpContext;
            Models.SocialMedia.Facebook.posts posts = await facebookClient.Posts();

            return(View(posts));
        }
Exemple #5
0
        public async Task <ActionResult> Posts()
        {
            var currentClaims = await UserManager.GetClaimsAsync(HttpContext.User.Identity.GetUserId());

            var accestoken = currentClaims.FirstOrDefault(x => x.Type == "urn:tokens:facebook");

            if (accestoken == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Token not found"));
            }

            string         url     = String.Format("https://graph.facebook.com/me?fields=id,name,feed.limit(500){{link,height,width,type,message,story,created_time,id,target,full_picture}}&access_token={0}", accestoken.Value);
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.Method = "GET";
            using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string       result = await reader.ReadToEndAsync();

                dynamic jsonObj = System.Web.Helpers.Json.Decode(result);
                Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonObj);
                ViewBag.JSON = result;
                string json = JsonConvert.SerializeObject(jsonObj);
                string path = @"C:\Big Data Analytics\Social data mining Technique\Assignment\fbdata.json";
                using (TextWriter tw = new StreamWriter(path))
                {
                    //foreach (var p in json)
                    // {
                    tw.WriteLine(json);
                    // }
                }
                var connectionString = "mongodb+srv://test:[email protected]/test?retryWrites=true&w=majority";


                var client = new MongoClient(connectionString);

                var database = client.GetDatabase("SocialMediaR");

                string text       = System.IO.File.ReadAllText(path);
                var    collection = database.GetCollection <BsonDocument>("FacebookR");
                var    aa         = new BsonDocument
                {
                    { "a", "aa" },
                    { "b", "bb" }
                };
                await collection.InsertOneAsync(aa);

                client.DropDatabase("SocialMedia" +
                                    "");
                MongoDB.Bson.BsonDocument docu
                    = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(result);
                await collection.InsertOneAsync(docu);


                return(View(posts));
            }
        }
Exemple #6
0
        public async Task <posts> Posts()
        {
            //Access Token
            await GetAccessToken();


            string url = String.Format("{0}{1}&access_token={2}", baseUrl, FeedUrl, "EAADtSvZAF4lgBALCZBrvAymqZC8Evwj1GrvxsPdl6v2mBV3rQLDcOxqxiZBU2ZBVO7ERIKygjYc9i7Xim7BUuD4cZCOpFXXB68aN4mWCVZCIiNUSvpqn0iI5cxeynADyQP9ZCMpMaSeRQVA9ZC9WrzuRjA0fumTCLT1QPqcGjV02JA8d931z9nXRfyWuLZCtYFhsPo0nyIHyUoKQZDZD");

            Console.WriteLine(url);

            //Get data
            dynamic jsonObj = await Get(url);

            //Convert JSON
            Models.SocialMedia.Facebook.posts posts =
                new Models.SocialMedia.Facebook.posts(jsonObj);


            using (SqlConnection connection = new SqlConnection("Data Source=DESKTOP-LNSE3O5;AttachDbFilename=|DataDirectory|SocialMediaReader2020.mdf;Initial Catalog=SocialMediaReader2020;Integrated Security=True"))
            {
                using (SqlCommand command = new SqlCommand())
                {
                    int      id           = jsonObj.id;
                    DateTime created_time = jsonObj.created_time;
                    string   src          = jsonObj.src;
                    int      width        = jsonObj.width;
                    int      height       = jsonObj.height;

                    command.Connection  = connection;           // <== lacking
                    command.CommandType = CommandType.Text;
                    command.CommandText = "INSERT into feed (src,width,height) VALUES (@src,@width,@height)";
                    command.Parameters.AddWithValue("@id", id);
                    command.Parameters.AddWithValue("@created_time", created_time);
                    command.Parameters.AddWithValue("@src", src);
                    command.Parameters.AddWithValue("@height", height);
                    command.Parameters.AddWithValue("@width", width);

                    try
                    {
                        connection.Open();
                        int recordsAffected = command.ExecuteNonQuery();
                    }
                    catch (SqlException)
                    {
                        // error here
                    }
                    finally
                    {
                        connection.Close();
                    }
                }

                return(posts);
            }
        }
        public async Task <posts> Posts()
        {
            //Access Token
            await GetAccessToken();

            string url = String.Format("{0}{1}&access_token={2}", baseUrl, FeedUrl, AccessToken);

            //Get data
            dynamic jsonObj = await Get(url);

            //Convert JSON
            Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonObj);
            return(posts);
        }
Exemple #8
0
        public async Task <ActionResult> Posts()
        {
            Models.SocialMedia.Facebook.FacebookClient facebookClient = new Models.SocialMedia.Facebook.FacebookClient();
            facebookClient.HttpContext = HttpContext;

            Models.SocialMedia.Facebook.posts posts = await facebookClient.Posts();

            return(View(posts));

            ////Get Access Token
            //var currentClaims = await UserManager.GetClaimsAsync(HttpContext.User.Identity.GetUserId());
            //var accesstoken = currentClaims.FirstOrDefault(x => x.Type == "urn:tokens:facebook");

            //if (accesstoken == null)
            //{
            //    return (new HttpStatusCodeResult(HttpStatusCode.NotFound, "Token not found."));
            //}

            ////Format a url to retrieve posts or feed data from Facebook
            //string url = String.Format("https://graph.facebook.com/me?fields=id,name,feed.limit(1000){{attachments,message,story,created_time,likes}}&access_token={0}", accesstoken.Value);

            ////Generate a web request using the url
            //HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            //request.Method = "GET";

            ////Ask for data from the server
            //using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            //{
            //    StreamReader reader = new StreamReader(response.GetResponseStream());

            //    //Place result into a string
            //    string result = await reader.ReadToEndAsync();

            //    //Convert result to JSON Object
            //    dynamic jsonObj = System.Web.Helpers.Json.Decode(result);

            //    Models.SocialMedia.Facebook.posts posts = new Models.SocialMedia.Facebook.posts(jsonObj);

            //    ViewBag.JSON = result;

            //    return View(posts);
            //}
        }