How to create the PHP curl flow for the authorization proces?

821 views
Skip to first unread message

Ged Evers

unread,
Jul 28, 2014, 2:37:49 PM7/28/14
to strav...@googlegroups.com
I am trying to get the Strava api to work with PHP.

When i use my access_token directly from the strava website, it all works ok, meaning that i get JSON results for streams, activities etc. 

When i try to do a GET request to Strava https://www.strava.com/oauth/authorize it does not work at all.

I used the next code:

$strava_url = "https://www.strava.com/oauth/authorize";
$params = http_build_query($fields);
$uri = $strava_url."?".$params;
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
 
$json_response = curl_exec($ch);
$error = curl_error( $curl );
$http_response_code = curl_getinfo($ch);
curl_close($ch);

Can someone please hint me how this should be done? When i enter the $uri manualy in the browser, it works fine. There must be something wrong with the curl setup...

Thx, Ged

Paul Mach

unread,
Jul 28, 2014, 3:38:05 PM7/28/14
to Ged Evers, strava-api
Hi Ged,

/oauth/authorize is the html page that users use to authorize you app, for example:

To complete the token exchange you want to POST to https://www.strava.com/oauth/token see the docs for more details. http://strava.github.io/api/v3/oauth/#post-token

Dr. Paul Mach
STRAVA


--
You received this message because you are subscribed to the Google Groups "Strava API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strava-api+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ged Evers

unread,
Jul 28, 2014, 4:38:53 PM7/28/14
to strav...@googlegroups.com, gedion...@gmail.com
Hi Paul,

Thx for the quick response.

I Know that the oauth link is ussed for users to authorize. But i want to sent the link as a GET request from my application, and not just have it link to it in HTML code. Is that not the correct way of doing it? When i type the URI in the browser it works fine and i get a code in the response, which i can POST to the token link (which i did not try, since i am not getting the response back in the token_exchange.php.

I think its a PHP related problem, and not so much Strava related.

KR/ Ged

Op maandag 28 juli 2014 21:38:05 UTC+2 schreef Paul:

Paul Mach

unread,
Jul 28, 2014, 4:41:28 PM7/28/14
to Ged Evers, strava-api
You want to send the user to that authorize page. That explains to them that they are allowing you to access their data. 

I don't understand why you would want to fetch the HTML in your code?

Dr. Paul Mach
STRAVA
Reply all
Reply to author
Forward
0 new messages