PHP code example of mkraemer / garmin-connect-activity-uploader

1. Go to this page and download the library: Download mkraemer/garmin-connect-activity-uploader 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/ */

    

mkraemer / garmin-connect-activity-uploader example snippets



use GuzzleHttp\Client as HttpClient;
use MKraemer\GarminConnect\SSO\SSO as GarminConnectSSO;
use MKraemer\GarminConnect\ActivityUploader\ActivityUploader as GarminConnectActivityUploader;

$client = new HttpClient();

$sso = new GarminConnectSSO(
        $client,
        'username',
        'password'
        );

$cookieJar = $sso();

$activityUploader = new GarminConnectActivityUploader($client, $cookieJar);

$fileInfo = new SplFileInfo('/path/to/garmin_device/Activities/2015-04-02.fit');

$result = $activityUploader($fileInfo);

switch ($result) {
    case GarminConnectActivityUploader::RESULT_UPLOAD_SUCCESSFUL:
        echo sprintf('%s successfully uploaded', $fileInfo->getFilename());
        break;

    case GarminConnectActivityUploader::RESULT_UPLOAD_DUPLICATE:
        echo sprintf('%s was already uploaded', $fileInfo->getFilename());
        break;
}