如何使用Python使用Strava API访问身份验证?

问题描述 投票:0回答:2

我正在启动一个小型python脚本(不是应用程序),无论何时在所需的文件夹中创建我的* .fit活动文件,都可以将它们上传到Strava上。

我计划要做的主要步骤是:

1. monitor *.fit file system modifications
2. access authentication to Strava to enable my program to upload files
   (This tool will be personal use only, thus I expect no need to authenticate every time uploading)
3. upload the file to my Strava account
4. automatically doing this fixed routine with the help of Windows Task Scheduler
   (For example, there will be 4-5 new riding activities generated in my computer folder, I expect this tool can automatically upload all of them once a week so that I do not need to manually complete the task.)

对于step2,即使通读Strava Authentication Documentation和其他人开发的一些源代码(例如toravir's "rk2s (RunKeeper 2 Strava)" project on GitHub),我实际上也不知道如何实现。我抓住了一些python模块,例如stravalib,swagger_client,请求,json等,以及诸如OAuth2的概念可能与step2相关,但我仍然无法将所有内容放在一起...

有经验的人可以给我一些有关step2实施的建议吗?或任何相关的阅读将是完美的!

也将非常欢迎和赞赏该项目其他部分的建议。

我非常感谢您:)

python api oauth-2.0 access-token strava
2个回答
0
投票

[我相信您需要使用OAuth进行身份验证才能上传您的活动,这几乎需要您具有一个Web服务器设置,Strava可以在您进行“授权”后将其发布回。我只是使用Rails&Heroku设置了身份验证块。

此链接提供了一个很好的流程图,说明需要发生的情况。https://developers.strava.com/docs/authentication/


0
投票

实际上看起来,如果您转到API Settings,则可以获取访问令牌并在那里刷新令牌。我也会检查Python Strava Library,但看起来您可以执行以下操作:

from stravalib.client import Client
access_token = 'your_access_token_from_your_api_application_settings_page'
refresh_token = 'your_refresh_token_from_your_api_application_settings_page' 

client = Client()

athlete = client.get_athlete()

您可能需要深入研究该库以找出上传的片段。

© www.soinside.com 2019 - 2024. All rights reserved.