Skip to content

Instantly share code, notes, and snippets.

@vladimir-paskov
Forked from erikdmitchell/webhook.php
Created February 19, 2024 07:29
Show Gist options
  • Select an option

  • Save vladimir-paskov/0de8f0c87f22dddc8059ddb544462e80 to your computer and use it in GitHub Desktop.

Select an option

Save vladimir-paskov/0de8f0c87f22dddc8059ddb544462e80 to your computer and use it in GitHub Desktop.
PHP Webhook setup for STRAVA API
<?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