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 Page_Load(object sender, EventArgs e) { //Setup the auth url string authUrl = "https://runkeeper.com/apps/authorize?client_id=" + ClientId + "&redirect_uri=" + HttpUtility.UrlEncode(RequestUri) + "&response_type=code"; AAuthAnchor.HRef = authUrl; //Initialize the healthgraph api - get a token or use an existing one saved to session TokenManager = new AccessTokenManager(ClientId, ClientSecret, RequestUri); if (string.IsNullOrEmpty(Code) == false) { //If we set the code in the url string, get a new access token and save it to the session TokenManager.InitAccessToken(Code); Token = TokenManager.Token; } else if (Token != null) { //Otherwise, if the access code saved in session is present we'll attempt to use that TokenManager.Token = Token; } if (Token != null) { DisplayHealthGraphSamples(); } }
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"))); } }