basvandorst/StravaPHP

Email is no longer available from Strava

fbonzon opened this issue · 16 comments

From the official Strava V3 API Changelog:

January 17, 2019
Removed email from athlete summary and athlete detail.

We need to deprecate and eventually remove the functions returning an athlete's email.

Yes, this is quite important. My Drupal client using this library is not working at the moment. Also we need to update the way we fetch and refresh authentication tokens. see: https://developers.strava.com/docs/oauth-updates/

Is there any update on this?

Does this still use forever tokens?

Does this still use forever tokens?

yes, it still uses permanent tokens.

Is it going to be a difficult job to move to the new system? I am not sure I fully understand the documentation.

@martynwheeler The easiest way to get the new Refresh Tokens is to use the new scope rules (https://developers.strava.com/docs/oauth-updates/). Using old scope rules only brings back Forever Tokens.

So instead of the old scopes:

$authUrl = $oauth->getAuthorizationUrl(
   [
      'scope' => [
         'public',
         // 'write',
         // 'view_private',
      ]
   ]
);

Use the new scopes:

$authUrl = $oauth->getAuthorizationUrl(
   [
      'scope' => [
           // 'read',
           // 'activity:read',
           // 'activity:write',
           // 'profile:write',
           'read_all',
           // 'activity:read_all',
           // 'profile:read_all',
           // 'view_private',
        ]
   ]
);

Then using the getAccessToken method like in the docs:

$token = $oauth->getAccessToken(
   'authorization_code',
   [
      'code' => $_GET['code']
   ]
);

This then gets a refresh token back and check if it's expired etc:

$token->getRefreshToken()

or

$token->getExpires()

🎉

Thank you, I (think) that I am already doing this. But i see no documentation for getRefreshToken()??? Here is my code:
`
/**
* @route("/", name="homepage")
*/
public function index(Request $request, StravaAPI $strava_api, RideData $rd)
{
//if code is set then grab and store
if ($request->query->get('code')) {
//'code' is set then grab the Strava token
$token = $strava_api->getOAuth()->getAccessToken(
'authorization_code',
['code' => $request->query->get('code')]
);
$request->getSession()->set('strava.token', $token->getToken());
} elseif (($this->getUser() !=null) and ($request->getSession()->get('strava.token') == null)) {
//User is logged in but no token is set then get authorization from Strava
if ($this->getUser()->getStravaID() != null) {
try {
$url = $strava_api->getOAuth()->getAuthorizationUrl([
'scope' => [
'read',
'activity:read',
]
]);
} catch (Exception $e) {
print $e->getMessage();
}
return new RedirectResponse($url);
}
}

public function getOAuth($url = 'homepage')
{
    $options = [
        'clientId'     => getenv('STRAVA_ID'),
        'clientSecret' => getenv('STRAVA_SECRET'),
        'redirectUri'  => $this->urlGen->generate($url, [], UrlGeneratorInterface::ABSOLUTE_URL)
    ];
    $oauth = new OAuth($options);
    return $oauth;
}

`

@martynwheeler This plugin uses the oAuth Client library dependency so you can use pretty much all methods from there:

https://github.com/thephpleague/oauth2-client/

Would it be a good idea to incorporate https://github.com/Edwin-Luijten/oauth2-strava into the code?

@martynwheeler You could probably use that instead, but then you don't get the methods to grab data easily. I've had no issues using this StravaPHP though once you just use the oAuth methods.

Stale issue message

@vredeling Can you provide a summary of what the outstanding issue is? Perusing this thread I haven't had any of the same problems in v2 so far.

@MGatner

January 15, 2019
Email address is no longer part of the profile:read_all scope and is removed from the athlete model.

This means that if you have an app that links the account of the app to your Strava profile based on the email-address, you need to rework that relationship. Basically, that means going over the codebase and remove references to email as a Athlete property and any derivatives thereof.

This doesn't appear to be an issue with the current library, as far as I can tell. No references to email anywhere. I have a hunch this won't apply to me at all, being a new user of the Strava API.

I do think there is a problem with emails,

public function userEmail($response)
for instance refers to a parent method that doesn't exist. Anyhoo, I'll have to dive into this myself.

Stale issue message