com.strava.v3.api
5.0.1
See the version list below for details.
dotnet add package com.strava.v3.api --version 5.0.1
NuGet\Install-Package com.strava.v3.api -Version 5.0.1
<PackageReference Include="com.strava.v3.api" Version="5.0.1" />
paket add com.strava.v3.api --version 5.0.1
#r "nuget: com.strava.v3.api, 5.0.1"
// Install com.strava.v3.api as a Cake Addin #addin nuget:?package=com.strava.v3.api&version=5.0.1 // Install com.strava.v3.api as a Cake Tool #tool nuget:?package=com.strava.v3.api&version=5.0.1
com.strava.v3.api
Important Notes (Read me first!)
This project was forked from the RobertEves92 repo, which in turn was forked from the original by sascha-simon, neither of which have been updated in a long time. It is therefore very possible that various aspects of the project don't work as originally intended, or don't work full stop, due to changes made by Strava in their API.
Latest version updated for Strava was updated in January 07, 2023
Feedback
If you have any feedback, bug reports or suggestions, feel free to add an issue to the repo and I'll look in to it
Getting an access token from Strava
You can get an access token from Strava by using one of the following methods:
- StaticAuthentication You can use this method if you already have an access token. You can either use the WebAuthentication class to get a access token from Strava or you can use your token, that you got when you registered your application.
StaticAuthentication auth = new StaticAuthentication("<insert token here>");
- WebAuthentication This procedure should be used, if you want to authorize your application for the first time. When an object is created and the GetTokenAsync() method is invoked, a browser window will open and you have to authorize the apllication. Once the button is clicked, Strava invokes a callback function. When you create a WebAuthentication object, a web server is started locally on your computer. Once the button is clicked, Strava invokes a callback function which is received by the callback server. You now have a working access token created specifically for your application. You can store this access token in a file on your hard disk, so you don't have to open a browser window every time. You should use some sort of cryptographic algorithm, to obfuscate the access token.
Upon the next start of the program, you can then load the token from your hard disk and use the StaticAuthentication method described above.
The date and time that the token expires will also be saved, so it is possible to check this and only obtain a new token when this is actually required.
Hints
When using the WebAuthentication method in your application, you have to start the application as an admin (at least when you acquire the access token). Strava sends back the access token via a callback. To receive this callback, a WebServer must be started locally. To start such a server, you need admin rights.
After you have received your token, you can save it to a file so you won't have to get a new token every time.
Using Strava.NET
General
Getting data from Strava is pretty straightforward. All you have to do, is to create a StravaClient object and pass a valid IAuthenticator object.
StaticAuthentication auth = new StaticAuthentication("<insert token here>");
StravaClient client = new StravaClient(auth);
Now you can use the client object to make some calls to Strava.
As of now, i only have implemented the async methods, regular methods will follow. Most of the methods are overwritten. When you don't need to pass a parameter to the method, the data will be of the currently authenticated athlete.
//Receive the currently authorized athlete
Athlete athlete = await client.Athletes.GetAthleteAsync();
When you pass a parameter to the method, you can get data from another athlete.
//Receive an other athlete
Athlete athlete = await client.Athletes.GetAthleteAsync("<id here>");
Limits
The usage of the Strava API is limited. There are two different limits, a short- and a long-term limit. The long term limit is 30.000 request per day, the short term limit is 600 request per 15 minutes. Whenever a request is made and an response is received, the limits are processed and saved in the static properties of the Limit class.
This class provides the following members:
Property | Description |
---|---|
Usage | The Usage data object has two properties, the short- and the long term usage. |
The Limit class also provides events you can subscribe to.
Athletes
The StravaClient offers the following methods:
Method | Return type | Description |
---|---|---|
GetAthleteAsync() | Athlete | Gets the currently authenticated athlete. |
GetAthleteAsync(String athleteId) | Athlete | Gets the profile from any athlete. |
GetFriendsAsync() | List<Athlete> | Gets the friends of the currently authenticated athlete. |
GetFriendsAsync(String athleteId) | List<Athlete> | Gets the friends of any athlete. |
GetFollowersAsync() | List<Athlete> | Gets the followers from the currently authenticated athlete. |
GetFollowersAsync(String athleteId) | List<Athlete> | Gets the followers of any athlete. |
GetBothFollowingAsync(String atheleteId) | List<Athlete> | Gets the athletes that both you and any athlete are following. |
UpdateAthlete(AthleteParameter parameter, String value) | Athlete | Updates a specified parameter of the currently authenticated athlete. Requires write permissions. |
UpdateAthleteSex(Gender gender) | Athlete | Updates the sex of the currently authenticated athlete. Requires write permissions. |
Examples
StaticAuthentication auth = new StaticAuthentication("<token here>");
StravaClient client = new StravaClient(auth);
//Receive the currently authenticated athlete
Athlete athlete = await client.Athletes.GetAthleteAsync();
StaticAuthentication auth = new StaticAuthentication("<token here>");
StravaClient client = new StravaClient(auth);
//Receive an other athlete
Athlete athlete = await client.Athletes.GetAthleteAsync("<id here>");
StaticAuthentication auth = new StaticAuthentication("<token here>");
StravaClient client = new StravaClient(auth);
//Get my followers
List<Athlete> athlete = await client.Athletes.GetFollowersAsync();
Activities
There are three types of activity objects:
- Activity
- ActivitySummary
- ActivityMeta
The Activity object contains all the information about an activity. An Activity object is only returned if you are the owner of the activity otherwise an ActivitySummary is returned.
An ActivityMeta object only contains the activity id and is returned if you load other data like a segment effort. The SegmentEffort object only contains an ActivityMeta member with the activity id. But you can use this id to get a more detailed version of the activity.
The AcitivtySummary and ActivityMeta classes were added to avoid some nasty NullPointerExceptions.
Method | Return type | Description |
---|---|---|
GetActivityAsync(string id) | Activity or ActivitySummary | Gets a detailed version of an activity if you are the owner of the activity. Otherwise an activity summary is returned. |
GetCommentsAsync(string activityId) | List<Comment> | Gets all the comments of the specified activity. |
GetKudosAsync(string activityId) | List<AthleteSummary> | Gets a list of athletes that kudoed the specified activity |
GetActivityZonesAsync(String activityId) | List<ActivityZone> | Gets a list of ActivityZones for the specified activity. (Premium Feature) |
GetActivityBeforeAsync(String id, DateTime before) | List<ActivitySummary> | Gets a list of activities that were recorded before the specified date. |
GetActivityAfterAsync(String id, DateTime after) | List<ActivitySummary> | Gets a list of activities that were recorded after the specified date. |
DeleteActivity(String activityId) | void | Deletes the specified activity. Requires you to be the owner of the activity and write permissions. |
Clubs
Method | Return type | Description |
---|---|---|
GetClubAsync(String clubId) | Club | Gets the club with the specified id. The club must either be public or you must be a member of the club to receive some data. |
GetClubsAsync() | List<Club> | Gets all the clubs of the currently authenticated athlete |
GetClubMembersAsync(String clubId) | List<AthleteSummary> | Gets all the members of the specified club. |
Gear
Segments
Method | Return type | Description |
---|---|---|
GetStarredSegmentsAsync() | List<SegmentSummary> | Returns a list of segments that the currently authenticated athlete has starred. |
Segment Efforts
Leaderboards
You can filter the leaderboard by various parameters like gender or weight. Please keep in mind that you need a Strava premium account to use filtering.
Method | Return type | Description |
---|---|---|
GetFullSegmentLeaderboardAsync(string segmentId) | Leaderboard | Returns the unfiltered leaderboard for the specified segment. |
GetSegmentLeaderboardAsync(string segmentId, Gender gender) | Leaderboard | Returns the leaderboard for the specified segment, filtered by gender. |
GetSegmentLeaderboardAsync(string segmentId, Gender gender, AgeGroup age) | Leaderboard | Returns the leaderboard for the specified segment, filtered by both gender and age group. (Premium Feature) |
GetSegmentLeaderboardAsync(string segmentId, Gender gender, WeightClass weight) | Leaderboard | Returns the leaderboard for the specified segment, filtered by both gender and weight class. (Premium Feature) |
Uploading an activity
You can use the UploadClient to upload an activity from a *.fit, *.tcx or a *.gpx file. I recommend that you create a StravaClient and use the predefined subclients.
After you've defined the file you want to upload, you can use the UploadStatusCheck class to check the status of your upload. There are events that are raised when a certain status of the upload is reached.
StaticAuthentication auth = new StaticAuthentication("<your token>");
Client.StravaClient client = new Client.StravaClient(auth);
UploadStatus status = await client.Uploads.UploadActivityAsync(@"F:\2014-03-22-14-43-55.fit", DataFormat.Fit);
UploadStatus s = await client.Uploads.CheckUploadStatusAsync(status.Id.ToString());
Console.WriteLine(s.Status);
UploadStatusCheck check = new UploadStatusCheck(_token, status.Id.ToString());
check.UploadChecked += delegate(object o, UploadStatusCheckedEventArgs args)
{
Console.WriteLine(args.Status);
};
check.Start();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.NETCore.Platforms (>= 7.0.0)
- Microsoft.NETCore.Targets (>= 5.0.0)
- Newtonsoft.Json (>= 13.0.2)
- System.Drawing.Common (>= 7.0.0)
- System.Runtime (>= 4.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.