예제 #1
0
        private async void fillPosts()
        {
            //create http client + set token
            HttpClient client = new HttpClient();

            //get all the links to the feeds
            string campusJson = await client.GetStringAsync("http://localhost:50103/api/Campus");

            var Campusses = JsonConvert.DeserializeObject <List <RootObject> >(campusJson);
            Dictionary <string, string> dicPage = new Dictionary <string, string>();

            foreach (RootObject c in Campusses)
            {
                dicPage.Add(c.Name, c.Feed);
                foreach (WindowsClient.Models.Training t in c.Trainingen)
                {
                    if (!dicPage.ContainsKey(t.Name))
                    {
                        dicPage.Add(t.Name, t.Feed);
                    }
                }
            }

            //facebook token
            string token = "EAACEdEose0cBAKPym9PzFo7ZAf0iqWA4LTcHTwcnvohMDzHGA6GVV91hGVS36XCfWBT7yjSHENhHoSTBiVyxi8TLulFZBnZAdGuoC6pfa3PvC5n57TLOhOknzQt9sRbb6Dk0ZAlZBoLyrI8ryC03ihKXg7pmzOmR8ozh1G1j2KAZDZD";

            //get all the facebooks posts
            try
            {
                foreach (KeyValuePair <string, string> entry in dicPage)
                {
                    //This crap page doesn't wanne share its feeds >=(
                    if (!entry.Key.Equals("HoGent Schoonmeersen"))
                    {
                        //set the appropriate url and get json
                        string oauthUrl = string.Format("https://graph.facebook.com/v2.8/{0}/feed?access_token={1}", entry.Value, token);
                        string json     = await client.GetStringAsync(oauthUrl);

                        //Debug.Write(json);
                        var result = JsonConvert.DeserializeObject <Wrapper>(json);

                        //convert the json to PostObjects
                        for (int i = 0; i < 5; ++i)
                        {
                            PostObject post = new PostObject()
                            {
                                id           = result.data[i].id,
                                story        = result.data[i].story,
                                message      = result.data[i].message,
                                created_time = result.data[i].created_time,
                                page         = entry.Key
                            };
                            //add retrieved post to posts
                            posts.Add(post);
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Er ging iets mis.");
                if (e.Message.Contains("400"))
                {
                    dialog = new Windows.UI.Popups.MessageDialog("Error 400 : Bad request. Refresh facebook token.\nhttps://developers.facebook.com/tools/explorer/");
                    await dialog.ShowAsync();
                }
                await dialog.ShowAsync();
            }
            catch (Exception e)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Er ging iets mis.");
                await dialog.ShowAsync();
            }

            string adminPosts = await client.GetStringAsync("http://localhost:50103/api/Posts");

            var result2 = JsonConvert.DeserializeObject <List <Post> >(adminPosts);

            foreach (Post p in result2)
            {
                PostObject PO = new PostObject();
                PO.page         = "Admin";
                PO.message      = p.Title + "\n\n" + p.Text;
                PO.created_time = p.Date;

                posts.Add(PO);
            }
        }
예제 #2
0
        private async void fillPostsMobile()
        {
            //create http client + set token
            HttpClient client = new HttpClient();

            //get all the links to the feeds
            Campus[] campussenObj = new Campus[]
            {
                new Campus()
                {
                    CampusId = 1, Name = "HoGent Schoonmeersen", City = "Gent", Street = "Valentin Vaerwyckweg", HouseNumber = "1", Telephone = "09 243 35 60", Feed = "Hogeschool-Gent-Campus-Schoonmeersen"
                },
                new Campus()
                {
                    CampusId = 2, Name = "HoGent Aalst", City = "Aalst", Street = "Arbeidstraat", HouseNumber = "14", Telephone = "09 243 38 00", Feed = "HoGentCampusAalst"
                }
            };
            Training[] trainingenObj = new Training[]
            {
                new Training()
                {
                    TrainingId = 1, Name = "Toegepaste Informatica", Description = "Computerrichting, hier start de leerling volledig vanaf de basis. Daarna heeft de leerling keuze om netwerken/programmeren te doen.", Feed = "hogenttoegepasteinformatica"
                },
                new Training()
                {
                    TrainingId = 2, Name = "Bedrijfsmanagement", Description = "Praktijk georienteerde richting over het managen van een bedrijf.", Feed = "hogentbedrijfsmanagement"
                },
                new Training()
                {
                    TrainingId = 3, Name = "Retail management", Description = "Voorbereiding op de job van strategisch manager in de detailhandel.", Feed = "hogentretailmanagement"
                },
                new Training()
                {
                    TrainingId = 4, Name = "Office management", Description = "Voorbereidende richting op het organiserende en coordinerende aspect in bedrijven.", Feed = "hogentofficemanagement"
                }
            };

            Dictionary <string, string> dicPage = new Dictionary <string, string>();

            foreach (Campus c in campussenObj)
            {
                dicPage.Add(c.Name, c.Feed);
            }

            foreach (Training t in trainingenObj)
            {
                dicPage.Add(t.Name, t.Feed);
            }

            //facebook token
            string token = "EAACEdEose0cBADR1gM0UaWcwyEg8gdZCABEZC6CLsAGG1yCievZAYCZB1AuZBbc6HI7n78ZCAJfvdP34ZAZBELSWnSXNcZC9dAcuDrRRJiu64PZAD0uJRpB3aeT0VEwlxpBEuA0qBqWm5CY2Efw3dWuZC2hyuvJu5Uuv835C8VYDmEFggZDZD";

            //get all the facebooks posts
            try
            {
                foreach (KeyValuePair <string, string> entry in dicPage)
                {
                    //This crap page doesn't wanne share its feeds >=(
                    if (!entry.Key.Equals("HoGent Schoonmeersen"))
                    {
                        //set the appropriate url and get json
                        string oauthUrl = string.Format("https://graph.facebook.com/v2.8/{0}/feed?access_token={1}", entry.Value, token);
                        string json     = await client.GetStringAsync(oauthUrl);

                        //Debug.Write(json);
                        var result = JsonConvert.DeserializeObject <Wrapper>(json);

                        //convert the json to PostObjects
                        for (int i = 0; i < 5; ++i)
                        {
                            PostObject post = new PostObject()
                            {
                                id           = result.data[i].id,
                                story        = result.data[i].story,
                                message      = result.data[i].message,
                                created_time = result.data[i].created_time,
                                page         = entry.Key
                            };
                            //add retrieved post to posts
                            posts.Add(post);
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Er ging iets mis.");
                if (e.Message.Contains("400"))
                {
                    dialog = new Windows.UI.Popups.MessageDialog("Error 400 : Bad request. Refresh facebook token.\nhttps://developers.facebook.com/tools/explorer/");
                    await dialog.ShowAsync();
                }
                await dialog.ShowAsync();
            }
            catch (Exception e)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Er ging iets mis.");
                await dialog.ShowAsync();
            }
        }