개발/C#

Strava API 관련 테스트

huiyu 2022. 2. 10. 21:21

Strava API guide 

1) Access Token 받아오기

https://javascript.plainenglish.io/strava-api-react-app-326e63527e2c?gif=true

 

How To Call Data From The Strava API In Your React App

Import your workouts from Strava API into your React App.

javascript.plainenglish.io

https://jessicasalbert.medium.com/holding-your-hand-through-stravas-api-e642d15695f2

 

Holding your hand through Strava’s API

When the YouTube walkthrough still isn’t enough — a beginner’s step-by-step guide to integrating Strava data into your application using…

jessicasalbert.medium.com

https://developers.strava.com/docs/getting-started/

 

Strava Developers

Make a cURL request to exchange the authorization code and scope for a refresh token, access token, and access token expiration date (step 7a from the graph). Replace the client_secret and code. The response should include the refresh token, access token,

developers.strava.com

 

Strava Settings/API

https://www.strava.com/settings/api

 

로그인 | Strava

 

www.strava.com

 

Strava API test : postman

https://web.postman.co/

Swagger UI :
https://developers.strava.com/playground/#/

 

Swagger UI

 

developers.strava.com

 

2) C# 코드로 받아오기
 - Strava Dotnet : https://github.com/chrisbarber7/stravadotnet/

 

GitHub - chrisbarber7/stravadotnet: Hopefully this small framework makes using the Strava API a little bit easier!

Hopefully this small framework makes using the Strava API a little bit easier! - GitHub - chrisbarber7/stravadotnet: Hopefully this small framework makes using the Strava API a little bit easier!

github.com

Test Code : 

using Strava.Activities;
using Strava.Athletes;
using Strava.Authentication;
using Strava.Clients;
using System;
using System.Collections.Generic;

namespace TestStrava
{
    class Program
    {
        static void Main(string[] args)
        {
            StaticAuthentication auth = new StaticAuthentication("----");
            StravaClient client = new StravaClient(auth);

            //Receive all the comments
            ActivityClient  test = client.Activities;

            List<ActivitySummary> list = test.GetActivities(1, 5);


            Console.WriteLine(String.Format("List Count : {0}", list.Count));
            foreach (ActivitySummary summary in list)
            {
                Console.WriteLine(String.Format("Name : {0}, Athlete: {1} Start Date : {2}", summary.Name, summary.Athlete.Id, summary.StartDate));
            }
        }
    }
}

아래 같이 볼 수 있다.(Athlete.Id로 출력할 것.)

Acitivites에서 확인할 수 있는 데이터 =->

{
    "resource_state": 2,
    "athlete": {
      "id": 24554267,
      "resource_state": 1
    },
    "name": "Evening Walk",
    "distance": 5057.4,
    "moving_time": 4131,
    "elapsed_time": 4229,
    "total_elevation_gain": 112.8,
    "type": "Walk",
    "id": 6660525777,
    "start_date": "2022-02-10T10:40:59Z",
    "start_date_local": "2022-02-10T19:40:59Z",
    "timezone": "(GMT+09:00) Asia/Seoul",
    "utc_offset": 32400,
    "location_city": null,
    "location_state": null,
    "location_country": null,
    "achievement_count": 0,
    "kudos_count": 0,
    "comment_count": 0,
    "athlete_count": 1,
    "photo_count": 0,
    "map": {
      "id": "a6660525777",
      "summary_polyline": "istcFc{{eWNIj@OTJJJJVb@j@HAb@Nv@bBXd@Xp@Pr@Dz@BHTPzA_@r@Bt@Zd@@h@RFCb@Dn@VPLj@r@j@h@v@x@\\Xn@X@`@DJHBHX?RGh@PP@JG`@AZI\\Cz@Ol@[h@g@VMDc@B_AOc@AYEk@Ac@I}Am@YQaAa@MKs@AGCIQYCe@P_BNM?EBc@Fm@h@[f@Wh@ERGf@At@`@lEAbBBJ?xABXLr@@f@AX?t@JtAWRAFd@fE?XJfAAHGHYHu@@kAN[CQOMM_@aAg@w@Sm@S_@Y]Qe@?IMUa@m@Mc@IOMa@a@}@YQOOg@q@OIa@c@KG]K]SKCE@e@OE?u@SWEGEk@MOGW?UISA{@WYCMGyAYkBg@OA]K]QMAOGI?CC]GeAGgBDWDKDEFa@@MFU@EJIDWCOBIHYAC@EFi@BEFE@GC]LGHKCO?OGOAg@@S@MJEJIGo@?UTc@DQDYCSRUDENEDsAMuAAm@KC@GJ[DYEKGK?IC]FGAMFG?KGI?IEc@Gg@HUNOACBKB_@K[A]Ii@EYIq@@QICEKa@Aa@IHEAGKGCSES@GQQAOLUS_@SGOGBEF@KGCi@U@AG?GCEMWOUM]KIAOGQSI[C?OKa@MMMBYCCKAGE_@[Wi@]]s@WKAOMIKSCU?OKWY[Om@m@OIS]QKCU?EEA?IEAUAg@g@QUe@OW[EOMQKKED?LK`@?NLJH?j@n@\\TNZ?NMb@Gt@Hn@?NKZATCJAx@ETC`@Mp@?NFREd@Kf@DVGn@QX?LMfAEDCJARIn@?VCHGh@@f@",
      "resource_state": 2
    },
    "trainer": false,
    "commute": false,
    "manual": false,
    "private": false,
    "visibility": "everyone",
    "flagged": false,
    "gear_id": null,
    "start_latlng": [
      37.47,
      126.96
    ],
    "end_latlng": [
      37.49,
      126.95
    ],
    "start_latitude": 37.47,
    "start_longitude": 126.95,
    "average_speed": 1.224,
    "max_speed": 3.426,
    "average_cadence": 56.7,
    "has_heartrate": true,
    "average_heartrate": 83.9,
    "max_heartrate": 112,
    "heartrate_opt_out": false,
    "display_hide_heartrate_option": true,
    "elev_high": 134.2,
    "elev_low": 40.9,
    "upload_id": 7083085315,
    "upload_id_str": "7083085315",
    "external_id": "garmin_push_8270870669",
    "from_accepted_tag": false,
    "pr_count": 0,
    "total_photo_count": 0,
    "has_kudoed": false
  },

이걸 유니티에서 그대로 사용해서 그려볼 수 있다.
(StravaDotnet.dll을 유니티 플러그인으로 사용. NewtonJson dll이 버전이 맞지 않아 새로 버전을 맞춰 빌드한 후 넣었다.)

728x90
반응형