PHP code example of kyoden / php-garmin-connect

1. Go to this page and download the library: Download kyoden/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/ */

    

kyoden / php-garmin-connect example snippets



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

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

  $filters = new \GarminConnect\ParametersBuilder\ActivityFilter();
  $filters->betweenDate(new \DateTime('2018-05-01'), new \DateTime('2018-05-31'));
  $filters->type(\GarminConnect\ActivityType::RUNNING);
  $filters->limit(1);

  $results = $GarminConnect->getActivityList($filters);
  foreach ($results as $activity) {print " - {$activity->activityName} at {$activity->startTimeLocal} (type: {$activity->activityType->typeKey})" . PHP_EOL;
   }

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

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

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

   try {
      $GarminConnect = new \GarminConnect\GarminConnect($arrCredentials);
      $fitlers = new \GarminConnect\GarminConnect\ParametersBuilder\ActivityFilter();
      $fitlers->betweenDate(new \DateTime('2018-06-01'), new \DateTime('2018-06-05'));
      $fitlers->type(\GarminConnect\GarminConnect\ActivityType::RUNNING);
      
      $obj_results = $GarminConnect->getActivityList($fitlers);
      print_r($obj_results);
   } catch (Exception $objException) {
      echo "Oops: " . $objException->getMessage();
   }

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

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

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