public ActionResult Activity()
 {
     // Request access to user profile
     var tokenManager = new AccessTokenManager("068e4fe819724d1b94a8889b6a23edbf", "152865a51b9f4b2d80248c5341de6dd5", "http://www.jmckillip.com", "b9be0fab840e458389349bee9ccb6c0a");
     var userRequest = new UsersEndpoint(tokenManager);
     var user = userRequest.GetUser();
     // Get user profile 
     var profileRequest = new ProfileEndpoint(tokenManager, user);
     var profile = profileRequest.GetProfile();
     // Get user name to pass to Activity view via ViewData Dictionary
     ViewData["name"] = profile.Name;
     //Retrieve activities
     var activitiesRequest = new FitnessActivitiesEndpoint(tokenManager, user);
     // Since the feed shows latest first, I only want to get that last one
     var activitiesPage = activitiesRequest.GetFeedPage(null, 1);
     // items[0].Uri will return the URI of the latest activity.
     var items = activitiesPage.Items;
     // Get the latest activity
     var latestActivity = activitiesRequest.GetActivity(items[0].Uri);
     return View(latestActivity);
 }
        protected void DisplayHealthGraphSamples()
        {
            PnlTokenSamples.Visible = true;
            LblAccessToken.Text = Token.AccessToken;
            LblAccessType.Text = Token.TokenType;

            //User Uri example
            var userRequest = new UsersEndpoint(TokenManager);
            var user = userRequest.GetUser();
            LblUserId.Text = user.UserID.ToString();
            LblUserStrengthTrainingActivities.Text = user.StrengthTrainingActivities;
            LblUserWeight.Text = user.Weight;
            LblUserSettings.Text = user.Settings;
            LblUserDiabetes.Text = user.Diabetes;
            LblUserTeam.Text = user.Team;
            LblUserSleep.Text = user.Sleep;
            LblUserFitnessActivities.Text = user.FitnessActivities;
            LblUserNutrition.Text = user.Nutrition;
            LblUserGeneralMeasurements.Text = user.GeneralMeasurements;
            LblUserBackgroundActivities.Text = user.BackgroundActivities;
            LblUserRecords.Text = user.Records;
            LblUserProfile.Text = user.Profile;

            //Get user profile
            var profileRequest = new ProfileEndpoint(TokenManager, user);
            var profile = profileRequest.GetProfile();
            //Optionally change and update it here
            //profile.AthleteType = "Hiker";
            //profile.AthleteType = "Hiker";
            //profile = profileRequest.UpdateProfile(profile);
            //Display user profile
            LblProfileName.Text = !string.IsNullOrEmpty(profile.Name) ? profile.Name : "N/A";
            LblProfileLocation.Text = !string.IsNullOrEmpty(profile.Location) ? profile.Location : "N/A";
            LblProfileAthleteType.Text = !string.IsNullOrEmpty(profile.AthleteType) ? profile.AthleteType : "N/A";
            LblProfileGender.Text = !string.IsNullOrEmpty(profile.Gender) ? profile.Gender : "N/A";
            LblProfileBirthday.Text = profile.Birthday.HasValue ? profile.Birthday.Value.ToShortDateString() : "N/A";
            LblProfileElite.Text = profile.Elite.ToString();
            LblProfileProfile.Text = profile.Profile;
            LblProfileSmallPicture.Text = !string.IsNullOrEmpty(profile.SmallPicture) ? profile.SmallPicture : "N/A";
            LblProfileNormalPicture.Text = !string.IsNullOrEmpty(profile.NormalPicture) ? profile.NormalPicture : "N/A";
            LblProfileMediumPicture.Text = !string.IsNullOrEmpty(profile.MediumPicture) ? profile.MediumPicture : "N/A";
            LblProfileLargePicture.Text = !string.IsNullOrEmpty(profile.LargePicture) ? profile.LargePicture : "N/A";

            //var measurementNew = new DiabetesMeasurementsNewModel
            //{
            //    Timestamp = DateTime.Now,
            //    Triglyceride = 150,
            //    PostToFacebook = false,
            //    PostToTwitter = false
            //};
            //var measurementRequest = new DiabetesMeasurementsEndpoint(TokenManager, user);
            //var uriOfMeasurement = measurementRequest.CreateMeasurement(measurementNew);
            //var measurementPage = measurementRequest.GetFeedPage();
            //string uriOfMeasurement = measurementPage.Items.First().Uri;
            //var measurementDetail = measurementRequest.GetMeasurement(uriOfMeasurement);
            //measurementDetail.Triglyceride = 40;
            //measurementDetail = measurementRequest.UpdateMeasurement(measurementDetail);
            //measurementRequest.DeleteMeasurement(uriOfMeasurement);

            //var measurementNew = new GeneralMeasurementsNewModel
            //{
            //    Timestamp = DateTime.Now,
            //    Testosterone = 40,
            //    PostToFacebook = false,
            //    PostToTwitter = false
            //};
            //var measurementRequest = new GeneralMeasurementsEndpoint(TokenManager, user);
            //var uriOfMeasurement = measurementRequest.CreateMeasurement(measurementNew);
            //var measurementPage = measurementRequest.GetFeedPage();
            //string uriOfMeasurement = measurementPage.Items.First().Uri;
            //var measurementDetail = measurementRequest.GetMeasurement(uriOfMeasurement);
            //measurementDetail.Testosterone = 100;
            //measurementDetail = measurementRequest.UpdateMeasurement(measurementDetail);
            //measurementRequest.DeleteMeasurement(uriOfMeasurement);

            //var backgroundNew = new BackgroundActivitiesNewModel
            //{
            //    Timestamp = DateTime.Now,
            //    Steps = 1000,
            //    PostToFacebook = false,
            //    PostToTwitter = false
            //};
            //var backgroundActivitiesRequest = new BackgroundActivitiesEndpoint(TokenManager, user);
            //var uriOfBackground = backgroundActivitiesRequest.CreateActivity(backgroundNew);
            //var backgroundPage = backgroundActivitiesRequest.GetFeedPage();
            //string uriOfBackground = backgroundPage.Items.First().Uri;
            //var backgroundDetail = backgroundActivitiesRequest.GetActivity(uriOfBackground);
            //backgroundDetail.CaloriesBurned = 100;
            //backgroundDetail = backgroundActivitiesRequest.UpdateActivity(backgroundDetail);
            //backgroundActivitiesRequest.DeleteActivity(uriOfBackground);

            //var strengthTrainingNew = new StrengthTrainingActivitiesNewModel
            //{
            //    StartTime = DateTime.Now,
            //    Notes = "Good exercise.",
            //    TotalCalories = 100,
            //    Exercises = new List<ExercisesModel>
            //    {
            //        new ExercisesModel
            //        {
            //            PrimaryType = "Barbell Curl",
            //            PrimaryMuscleGroup = "Arms",
            //            Sets = new List<SetsModel>
            //            {
            //                new SetsModel
            //                {
            //                    Weight = 200,
            //                    Repetitions = 4
            //                }
            //            }
            //        }
            //    },
            //    PostToFacebook = false,
            //    PostToTwitter = false
            //};
            //var strengthTrainingRequest = new StrengthTrainingActivitiesEndpoint(TokenManager, user);
            ////var uriOfStrengthTraining = strengthTrainingRequest.CreateActivity(strengthTrainingNew);
            //var activitiesPage = strengthTrainingRequest.GetFeedPage();
            //string uriOfStrengthTraining = activitiesPage.Items.First().Uri;
            //var activitiesDetail = strengthTrainingRequest.GetActivity(uriOfStrengthTraining);
            //activitiesDetail.TotalCalories = 200;
            //activitiesDetail = strengthTrainingRequest.UpdateActivity(activitiesDetail);
            //strengthTrainingRequest.DeleteActivity(uriOfStrengthTraining);

            //var sleepRequest = new SleepEndpoint(TokenManager, user);
            //var sleepNew = new SleepNewModel
            //{
            //    Timestamp = DateTime.Now,
            //    TimesWoken = 3,
            //    PostToTwitter = false,
            //    PostToFacebook = false
            //};
            //var uriOfSleep = sleepRequest.CreateSleep(sleepNew);
            //var sleepPage = sleepRequest.GetFeedPage();
            //var sleepDetail = sleepRequest.GetSleep(uriOfSleep);

            //var uriOfSleep = sleepPage.Items.First().Uri;
            //var sleepDetail = sleepRequest.GetSleep(uriOfSleep);
            //sleepDetail.Rem = 180;
            //sleepDetail = sleepRequest.UpdateSleep(sleepDetail);

            //sleepRequest.DeleteSleep(uriOfSleep);

            //int test = 4;
            //var settingsRequest = new SettingsEndpoint(TokenManager, user);
            //var settings = settingsRequest.GetSettings();
            //settings.FirstDayOfWeek = "Monday";
            //settings = settingsRequest.UpdateSettings(settings);

            //var streetTeamRequest = new StreetTeamEndpoint(TokenManager, user);
            //var streetTeamItems = streetTeamRequest.GetFeedPage(pageIndex: 1, pageSize: 2);
            //var uri = streetTeamRequest.CreateTeamInvitation(new StreetTeamInvitationsModel { UserID = 7072229 });
            //var results = streetTeamRequest.GetStreetTeam(uri);

            //var nutritionNew = new NutritionNewModel
            //{
            //    Timestamp = DateTime.Now,
            //    Fat = 200,
            //    PostToFacebook = false,
            //    PostToTwitter = false
            //};
            //var nutritionRequest = new NutritionEndpoint(TokenManager, user);
            //var uriOfNutrition = nutritionRequest.CreateNutrition(nutritionNew);
            //var uriOfNutrition = nutritionRequest.GetFeedPage().Items.First().Uri;
            //nutritionRequest.DeleteNutrition(uriOfNutrition);

            //var weightRequest = new WeightEndpoint(TokenManager, user);
            /*
            var weightNew = new WeightNewModel
            {
                Timestamp = DateTime.Now,
                Weight = 90,
                PostToFacebook = false,
                PostToTwitter = false
            };
            var test = weightRequest.CreateWeight(weightNew);
            */
            //var weightItems =  weightRequest.GetFeedPage().Items;
            //var weightItem = weightItems.First();
            /*
            var weightDetail = weightRequest.GetWeight(weightItem.Uri);
            weightDetail.Bmi = 240;
            weightDetail = weightRequest.UpdateWeight(weightDetail);
            */
            //weightRequest.DeleteWeight(weightItem.Uri);

            //var activitiesRequest = new FitnessActivitiesEndpoint(TokenManager, user);
            /*
            var newActivity = new FitnessActivitiesNewModel
            {
                Type = "Running",
                StartTime = DateTime.Now,
                Duration = 50,
                Notes = "blah6!"
            };
            var uri = activitiesRequest.CreateActivity(newActivity);
            */
            //var activitiesItem = activitiesRequest.GetFeedPage(pageSize: 2, noLaterThan: new DateTime(2013, 6, 1)).Items.FirstOrDefault();
            //if (activitiesItem != null)
            //{
            //    var activitiesDetail = activitiesRequest.GetActivity(activitiesItem.Uri);

                //Get associated comments
            //    var commentRequest = new CommentThreadsEndpoint(TokenManager);
            //    var commentThread = commentRequest.GetCommentThread(activitiesDetail.Comments);

            //    var newComment = new CommentsNewModel
            //    {
            //        Comment = "Here we go!"
            //    };
            //    commentRequest.CreateComment(newComment, activitiesDetail.Comments);
                //commentRequest.CreateCommentAsync(() => { }, (ex) => { }, newComment, activitiesDetail.Comments);

            //    commentThread = commentRequest.GetCommentThread(activitiesDetail.Comments);

                //Retrieve and update an activity
                //var activitiesDetail = activitiesRequest.GetActivity(activitiesItem.Uri);
                //activitiesDetail.Type = "Running";
                //activitiesDetail.Equipment = "None";
                //activitiesDetail.AverageHeartRate = null;
                //activitiesDetail.Notes = "Testing is fun.";
                //activitiesRequest.UpdateActivity(activitiesDetail);

                //Delete the activity
                //activitiesRequest.DeleteActivity(activitiesDetail.Uri);
               // }

            //var recordsRequest = new RecordsEndpoint(TokenManager, user);
            //var items = recordsRequest.GetRecordsFeed();
            //int test = 4;
        }
        protected void AttemptAuth(object sender, EventArgs e)
        {
            _clientIdEntry.FetchValue();
            ClientId = _clientIdEntry.Value;
            _clientSecretEntry.FetchValue();
            ClientSecret = _clientSecretEntry.Value;
            _requestUriEntry.FetchValue();
            RequestUri = _requestUriEntry.Value;

            if ((string.IsNullOrEmpty(ClientId)) || (string.IsNullOrEmpty(ClientSecret)) || (string.IsNullOrEmpty(RequestUri)))
            {
                UIAlertView firstPageValidationAlert = new UIAlertView("Whoops!", "Please provide a Client Id, Client Secrent and Request Uri.", null, "Okay");
                firstPageValidationAlert.Show();
            }
            else
            {
                //Elements for Second Page - authorization
                var secondPage = new UIViewController();
                secondPage.Title = "Authorize";
                var authorizeWebView = new UIWebView(secondPage.View.Frame);
                secondPage.View.AddSubview(authorizeWebView);
                viewController.VisibleViewController.NavigationController.PushViewController(secondPage, true);
                authorizeWebView.LoadFinished += delegate(object s, EventArgs ev) {
                    string currentUrl = authorizeWebView.Request.Url.AbsoluteString;
                    const string CodeIdentifier = "code=";
                    if (currentUrl.Contains(CodeIdentifier))
                    {
                        //We've received an authorization code - initialize the token manager to get a create a token
                        Code = currentUrl.Substring(currentUrl.IndexOf(CodeIdentifier) + CodeIdentifier.Length);
                        TokenManager = new AccessTokenManager(ClientId, ClientSecret, RequestUri);
                        InvokeOnMainThread(() => {
                            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
                        });
                        TokenManager.InitAccessToken(Code);
                        var userRequest = new UsersEndpoint(TokenManager);
                        User = userRequest.GetUser();
                        var profileRequest = new ProfileEndpoint(TokenManager, User);
                        Profile = profileRequest.GetProfile();
                        InvokeOnMainThread(() => {
                            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                        });
                        ShowUserAndProfile();
                    }
                };
                authorizeWebView.LoadRequest(new NSUrlRequest(new NSUrl(HealthGraphAuthorizeEndpoint + "?client_id=" + ClientId + "&redirect_uri=" + HttpUtility.UrlEncode(RequestUri) + "&response_type=code")));
            }
        }