PHP code example of dawguk / php-garmin-connect

1. Go to this page and download the library: Download dawguk/php-garmin-connect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dawguk / php-garmin-connect example snippets



$arrCredentials = array(
   'username' => 'xxx',
   'password' => 'xxx',
);

try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);

   $objResults = $objGarminConnect->getActivityList(0, 1, 'cycling');
   foreach($objResults->results->activities as $objActivity) {
      print_r($objActivity->activity);
   }

} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->getActivityTypes();
   foreach ($obj_results->dictionary as $item) {
      print_r($item);
   }

   } catch (Exception $objException) {
      echo "Oops: " . $objException->getMessage();
   }

   try {
      $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
      $obj_results = $objGarminConnect->getActivityList(0, 1);
      print_r($obj_results);
   } catch (Exception $objException) {
      echo "Oops: " . $objException->getMessage();
   }

try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->getActivitySummary(593520370);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->getActivityDetails(593520370);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

   try {
      $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
      $obj_results = $objGarminConnect->getDataFile(\dawguk\GarminConnect::DATA_TYPE_GPX, 593520370);
      print_r($obj_results);
   } catch (Exception $objException) {
      echo "Oops: " . $objException->getMessage();
   }


try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->getWorkoutList(0, 10);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $data = ''; 
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->createWorkout($data);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->deleteWorkout(593520370);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $data = '';
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->createStepNote(593520370, 'Hello World', 123456789);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}

try {
   $data = '';
   $objGarminConnect = new \dawguk\GarminConnect($arrCredentials);
   $obj_results = $objGarminConnect->scheduleWorkout(593520370, $data);
   print_r($obj_results);
} catch (Exception $objException) {
   echo "Oops: " . $objException->getMessage();
}