MIT License

项目介绍

iamstuartwilson/strava 是一个托管在 GitHub 上的开源项目,主要使用 PHP 编写,采用 MIT License 许可证,目前获得 123 个 Star、23 次 Fork。

仓库全名
iamstuartwilson/strava
开源许可证
MIT License
Star 数
123
Fork 数
23
未关闭 Issue
7

README 摘要

StravaApi The class simply houses methods to help send data to and receive data from the API. Please read the API documentation to see what endpoints are available. There is no file upload support at this time. Installation With Composer Or add it manually to your composer.json: Manually Copy StravaApi.php to your project and require it in your application as described in the next section. Getting Started…

完整内容见 GitHub 原始 README 或本页 。

常见问题

strava 用什么语言开发?

主要使用 PHP 编写,采用 MIT License 许可证,目前有 123 个 Star。

strava 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 strava 的源码?

可以直接克隆仓库:git clone https://github.com/iamstuartwilson/strava.git,默认分支为 master;安装与运行步骤见仓库 README。

strava 最近还在维护吗?

仓库最近一次更新为 2020年9月15日,当前有 7 个未关闭 Issue;Star 数为 123,可作为社区活跃度的参考。

关于

PHP Class for the Strava API (v3)

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
187
价值分
82
活跃状态
活跃

README

Build Status Minimum PHP Version Packagist Packagist Downloads

StravaApi

The class simply houses methods to help send data to and receive data from the API. Please read the API documentation to see what endpoints are available.

There is no file upload support at this time.

Installation

With Composer

composer require iamstuartwilson/strava

Or add it manually to your composer.json:

{
    "require" : {
        "iamstuartwilson/strava" : "^1.4"
    }
}

Manually

Copy StravaApi.php to your project and require it in your application as described in the next section.

Getting Started

Instantiate the class with your client_id and client_secret from your registered app:

require_once 'StravaApi.php';

$api = new Iamstuartwilson\StravaApi(
    $clientId,
    $clientSecret
);

If you’re just testing endpoints/methods you can skip the authentication flow and just use the access token from your settings page.

You will then need to authenticate your strava account by requesting an access code. You can generate a URL for authentication using the following method:

$api->authenticationUrl($redirect, $approvalPrompt = 'auto', $scope = null, $state = null);

When a code is returned you must then exchange it for an access token and a refresh token for the authenticated user:

$result = $api->tokenExchange($code);

The token exchange result contains among other data the tokens. You can access them as attributes of the result object:

$accessToken = $result->access_token;
$refreshToken = $result->refresh_token;
$expiresAt = $result->expires_at;

Before making any requests you must set the access and refresh tokens as returned from your token exchange result or via your own private token from Strava:

$api->setAccessToken($accessToken, $refreshToken, $expiresAt);

Example oAuth2 Authentication Flow

examples/oauth-flow.php demonstrates how the oAuth2 authentication flow works.

  1. Choose how to load the StravaApi.php – either via Composer autoloader or by manually requiring it.
  2. Replace the three config values CALLBACK_URL, STRAVA_API_ID, and STRAVA_API_SECRET at the top of the file
  3. Place the file on your server so that it’s accessible at CALLBACK_URL
  4. Point your browser to CALLBACK_URL and start the authentication flow.

The scripts prints a lot of verbose information so you get an idea on how the Strava oAuth flow works.

Example Requests

Once successfully authenticated you’re able to communicate with Strava’s API.

All actions that change Strava contents (post, put, delete) will need the scope set to write in the authentication flow.

Get Athlete Stats

$api->get('athletes/:id/stats');

List Athlete Activities

Some API endpoints support GET parameters:

$api->get(
    'athlete/activities',
    [
        'page' => 2,
        'per_page' => 10,
    ]
);

Post a new activity

$api->post(
    'activities', 
    [
        'name' => 'API Test',
        'type' => 'Ride',
        'start_date_local' => date('Y-m-d\TH:i:s\Z'),
        'elapsed_time' => 3600,
    ]
);

Update a athlete’s weight

$api->put('athlete', ['weight' => 70]);

Releases

See CHANGELOG.md.

评论

暂无评论