Created
September 6, 2021 01:18
-
-
Save erikdmitchell/2e165c57e618de14e1b208fceba2ee65 to your computer and use it in GitHub Desktop.
PHP Webhook setup for STRAVA API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_GET['hub_challenge'])) { | |
$data = ['hub.challenge' => $_GET['hub_challenge']]; | |
header("HTTP/1.1 200 OK"); | |
header('Content-Type: application/json; charset=utf-8'); | |
echo json_encode($data); | |
exit; | |
} | |
$client_id = '5'; | |
$client_secret = '7b2946535949ae70f015d696d8ac602830ece412'; | |
$callback_url = 'http://a-valid.com/url/webhook.php'; /* this should be the same URL as this page */ | |
$verify_token = 'STRAVA'; | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => "https://www.strava.com/api/v3/push_subscriptions?client_id={$client_id}&client_secret={$client_secret}&callback_url={$callback_url}&verify_token={$verify_token}", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => '', | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 0, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => 'POST', | |
)); | |
$response = curl_exec($curl); | |
curl_close($curl); | |
echo $response; /* will return the id or an error message */ | |
// store and/or process id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment