static void Main(string[] args) { // Configure OAuth2 access token for authorization: strava_oauth //Configuration.Default.AccessToken = "31a808cc0c54980db382e99ad2cc5bcfec97ebed"; /// ATHLETE DETAILS - WORKING - just need to update access_token try { var apiClient = new ApiClient(); apiClient.AccessToken = "1a8c919b477c0c7b03e218a41267636f80b6691e"; var apiInstance = new AthletesApi(apiClient); var result = apiInstance.GetLoggedInAthlete(); Debug.WriteLine(result); } catch (Exception ex) { Debug.Print("Exception when calling AthletesApi.GetLoggedInAthlete: " + ex.Message); } /// Activity DETAILS - update access_token with the current activity:read token try { var apiClientActivity = new ApiClient(); apiClientActivity.AccessToken = "17417ac5199f23d2904341aa48c234ed5e932812"; //activity:read token var apiInstance = new ActivitiesApi(apiClientActivity); var result = apiInstance.GetLoggedInAthleteActivities(null, null, page: 1, perPage: 30); float? distance = 0.0F; float? time = 0.0F; DateTime fromDate = DateTime.Parse("01/09/2019"); foreach (SummaryActivity activity in result) { if ((activity.Type.ToLower() == "ride") && (activity.Name.ToLower() != "spinning")) { if (activity.StartDate > fromDate) { distance += activity.Distance; time += activity.MovingTime; } } } Console.WriteLine(string.Format(@"Total distance on bike since {0:dd/MM/yyyy} is {1:0} km", fromDate, distance / 1000)); Console.WriteLine(string.Format(@"Total time on bike was {0:0.00} hrs", time / 3600)); } catch (Exception ex) { Debug.Print("Exception when calling ActivitiesApi.GetLoggedInAthleteActivities: " + ex.Message); } }
public static async Task GetAuthenticatedAthleteAsync() { //Получаем токен TokenModel token; token = Token.RenewToken(); Configuration.ApiKey.Add("access_token", token.Access_token); Configuration.ApiKey.Add("refresh_token", token.Refresh_token); Console.WriteLine(token.Access_token); //Подключаемся к БД string connString = "mongodb://192.168.1.200:27017"; MongoClient client = new(connString); IMongoDatabase mongoDatabase = client.GetDatabase("strava"); //Получаем данные и сохраняем в БД var apiInstance = new AthletesApi(); try { // Get Authenticated Athlete DetailedAthlete result = apiInstance.GetLoggedInAthlete(); var collection = mongoDatabase.GetCollection <AuthenticatedAthlete>("user"); AuthenticatedAthlete athlete = new() { Id = (int)result.Id, Resource_state = (int)result.ResourceState, Firstname = result.Firstname, Lastname = result.Lastname, City = result.City, State = result.State, Country = result.Country, Profile = result.Profile, Created_at = (DateTime)result.CreatedAt }; await collection.InsertOneAsync(athlete); Console.WriteLine(result); } catch (Exception e) { Console.WriteLine(e.Message); } }