cancel
Showing results for 
Search instead for 
Did you mean: 

Api in C#

MxSport
Shkhara

In https://developers.strava.com/docs/reference/ there are examples in C# using the com.strava.api.v3.api libraries, but where download the libraries from?
I tried downloading from https://github.com/tdao7/.Net-Strava-API and some api calls work, but it is different from the examples in the documentation and other api calls don't work.

4 REPLIES 4

MxSport
Shkhara

If Strava provides examples in C#, I think it's fair to expect them to work.
It's a bit strange to provide examples based on external libraries and then not care about whether these libraries are updated.
However, I made do on my own without using any libraries using just httpclient class.

That's a fair point, unfortunately, not only for Strava but other APIs are running in similar fashion. The most used languages for the API seem to survive while others deprecate and drift. I guess we can only ask what are the plans for the library in the future from Strava devs.

I report below the Strava example and my example without using the libraries.
My example has a similar number of lines and is more readable, so it would have taken Strava very little time to publish examples that work.

Strava example:

using System;
using System.Diagnostics;
using com.strava.api.v3.Api;
using com.strava.api.v3.Client;
using com.strava.api.v3.Model;

namespace Example
{
    public class getLoggedInAthleteExample
    {
        public void main()
        {
            
            // Configure OAuth2 access token for authorization: strava_oauth
            Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new AthletesApi();

            try
            {
                // Get Authenticated Athlete
                DetailedAthlete result = apiInstance.getLoggedInAthlete();
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling AthletesApi.getLoggedInAthlete: " + e.Message );
            }
        }
    }
}

 

My Example:

using System.Net;

namespace Example
{
    public class getLoggedInAthleteExample
    {
        public void main()
        {
		
			HttpClient Client = new();
			HttpRequestMessage Request = new(HttpMethod.Get, "https://www.strava.com/api/v3/athletes/{id}/stats?access_token={access_token}");
			
			HttpResponseMessage Response = await Client.SendAsync(Request);
			try
			{
				HttpResponseMessage Response2 = Response.EnsureSuccessStatusCode();
			}
			catch (Exception ex)
			{
				Debug.Print("Exception: " + e.Message );
				return;
			}
			
			string result = await Response.Content.ReadAsStringAsync();
			Debug.WriteLine(result);
			
        }
    }
}


 

 

meistars
Shkhara

The readme first says that these libraries are not frequently catching up with Strava API. Use your own models and http client or ideally contribute to the opensource.