Esempio n. 1
0
        //load friends list
        public async void loadFriends(Grid friendGrid, ProgressBar progressBar)
        {
            //the url to get our friends
            var url = "https://api.foursquare.com/v2/users/self/friends?oauth_token=" + App.accessToken + "&v=" + App.date;

            //bool for error
            bool error = false;

            //string to hold response
            string response = null;

            try
            {
                response = await client.GetStringAsync(url);
            }
            catch
            {
                //set error to true if exception was thrown
                error = true;
            }

            //if no error then deserialize
            if (!error)
            {
                //bool for json errors
                bool jsonError = false;

                //object to deserialize to
                FriendsClass.RootObject fc = null;
                try
                {
                    //deserialize data
                    fc = JsonConvert.DeserializeObject <FriendsClass.RootObject>(response);
                }
                catch
                {
                    jsonError = true;
                }

                //if no error lets put items into list
                if (!jsonError)
                {
                    for (int x = 0; x < fc.response.friends.count; x++)
                    {
                        FriendItem.Add(new FriendItem()
                        {
                            hometown = fc.response.friends.items[x].homeCity,
                            id       = fc.response.friends.items[x].id,
                            name     = fc.response.friends.items[x].firstName + " " + fc.response.friends.items[x].lastName,
                            image    = fc.response.friends.items[x].photo.prefix + "100x100" + fc.response.friends.items[x].photo.suffix
                        });
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        friendGrid.Visibility  = Visibility.Visible;
                        progressBar.Visibility = Visibility.Collapsed;
                        progressBar.IsEnabled  = false;
                    });
                }
            }
        }