Comments (7)
Turns out I can't use the API for my issue anyway. Closing. Thanks for the feedback.
from stravaphp.
Hi there, it would be useful to see your code examples in your implementation to gain a clearer understanding of what you are doing. Please could you provide these
from stravaphp.
In trying to get a token, I am doing this:
$client = new \Strava\API\OAuth([
'clientId' => $clientId,
'clientSecret' => $token,
'redirectUri' => $myRedirectUrl, ]);
\header('location: ' . $client->getAuthorizationUrl(['scope' => ['read', ]]));
Then on the redirect page:
$token = $client->getAccessToken('authorization_code', ['code' => $_GET['code']]);
$bearerToken = $token->getToken();
$refreshToken = $token->getRefreshToken();
One question is how do I refresh the token?
from stravaphp.
As far as I can tell, the above code should work - this is exactly how I access the tokens.
Your error seems to be coming from the AccessToken
constructor. Have the checked the response you are getting from Strava?
from stravaphp.
One question is how do I refresh the token?
@phpfui you can call the following:
$newAccessToken = $client->getAccessToken('refresh_token', [
'refresh_token' => $oldAccessToken->getRefreshToken(),
]);
Where $client
in an instance of Strava\API\OAuth
(it is probably better to name this $oauth
to prevent confusion with Strava\API\Client
).
from stravaphp.
Thanks for getting back to me. Turns out the Strava API will not get me what I want, which is mileage and elevation of any public activity. The code was trivial once I looked at the HTML, which Strava has conveniently structured well.
<?php
namespace App\Model;
class Strava
{
private function __construct(private array $data)
{
}
public function getMileage() : float
{
return (float)$this->data['mi'] ?? 0;
}
public function getElevationFeet() : int
{
return (int)$this->data['ft'] ?? 0;
}
public static loadFromActivityId(string $activityId) : ?\App\Model\Strava
{
$url = 'https://www.strava.com/activities/' . $activityId;
$html = file_get_contents($url);
if (! $html)
{
return null;
}
$dom = new \voku\helper\HtmlDomParser($html);
$parts = [];
foreach ($dom->find('.unit') as $node)
{
$unit = $node->text();
$value = str_replace([' ' . $unit, ','], '', $node->parentNode()->text());
$parts[$unit] = $value;
}
return new \App\Model\Strava($parts);
}
}
I am only using this in the US, so miles and feet, but I imagine it would be easy to also do the metric pages as well.
Thanks again for your library and support.
from stravaphp.
@phpfui Does this issue still require support or has it been resolved?
from stravaphp.
Related Issues (20)
- Refresh Tokens Update HOT 2
- Integration with Laravel project
- Handling Strava's conversion to oauth2 HOT 11
- Is this repo still maintained? HOT 6
- getAthleteActivities is buggy when using parameters
- getResponse doesn't throw, it already catches HOT 3
- PHPUnit tests fail when running locally HOT 2
- Laravel 8 incompatibility HOT 6
- Can you do a point release? HOT 5
- Where is autoload.php HOT 2
- Upload gpx file failed HOT 1
- Wrong scopes in README.md code examples HOT 1
- Library Compatibility HOT 11
- GitHub Link Broken HOT 3
- Scrutinizer HOT 3
- Setup Packagist for automatic updates HOT 9
- Webhook Subscriptions HOT 2
- Fix tests after type hints HOT 1
- getSegmentLeaderboard not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stravaphp.