Git Product home page Git Product logo

Comments (7)

phpfui avatar phpfui commented on August 20, 2024 1

Turns out I can't use the API for my issue anyway. Closing. Thanks for the feedback.

from stravaphp.

djjavo avatar djjavo commented on August 20, 2024

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.

phpfui avatar phpfui commented on August 20, 2024

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.

djjavo avatar djjavo commented on August 20, 2024

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.

djjavo avatar djjavo commented on August 20, 2024

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.

phpfui avatar phpfui commented on August 20, 2024

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.

vredeling avatar vredeling commented on August 20, 2024

@phpfui Does this issue still require support or has it been resolved?

from stravaphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.