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.
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.
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);
}
}
}
It seems to me that we are going around the problem.
I think that, instead of making a non-working example that uses external libraries, it would have been enough to make a simple and working example like the one in my example.
You seem to be conflating API usage examples with an SDK.
Strava don’t make a SDK or any libraries (nuget packages) for C#. This isn’t unusual and as a developer we need to not rely on API libraries and know how to build integrations ourselves just using http clients and REST.
You have a point that Strava should keep examples up-to-date if they are going to provide them.
No, I'm not getting confused at all.
Rather, you've confused what a usage example should be in a given language: a usage example should simply show how to use an API with a given language, and, obviously, the example should work, and instead it doesn't work at all.
It doesn't matter if Strava decides whether to use external libraries or language-specific instructions, what matters is that the example should work, and instead it doesn't work at all.
Reply
Login to the community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.