PHP code example of jyokum / healthgraph

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

    

jyokum / healthgraph example snippets





use HealthGraph\Authorization;

$client_id = 'xxxxxxxxxxxxxxxxxxxxx';
$redirect_url = 'http://example.com/authorize';

// Link
$link = Authorization::getAuthorizationLink($client_id, $redirect_url);
echo "<a href='$link'>Connect</a>";

// Button
$button = Authorization::getAuthorizationButton($client_id, $redirect_url);
echo $button['html'];


use HealthGraph\Authorization;

$client_id = 'xxxxxxxxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxxxxxxxx';
$redirect_url = 'http://example.com/authorize';

if (isset($_REQUEST['code'])) {
    $token = Authorization::authorize($_GET['code'], $client_id, $client_secret, $redirect_url);
    some_function_to_save_the_token($token);
}


use HealthGraph\Authorization;

$token = some_function_to_retrieve_the_token();
Authorization::deauthorize($token->access_token);


use HealthGraph\HealthGraphClient;

$token = some_function_to_retrieve_the_token();

$hgc = HealthGraphClient::factory();
$hgc->getUser(array(
    'access_token' => $token['access_token'],
    'token_type' => $token['token_type'],
));

// get profile
$hgc->GetProfile();

// get settings
$hgc->GetSettings();

// get fitness activity list
$activities = $hgc->FitnessActivityFeed()->getAll();

$hgc = HealthGraphClient::factory();
$hgc->getUser(array(
    'access_token' => $token['access_token'],
    'token_type' => $token['token_type'],
));
$data = array('athlete_type' => 'Athlete');
$hgc->UpdateProfile($data);

$hgc = HealthGraphClient::factory();
$hgc->getUser(array(
    'access_token' => $token['access_token'],
    'token_type' => $token['token_type'],
));

// Get the entire feed, this could return a lot of data.
$command = $hgc->getIterator('GetFitnessActivityFeed');
$result = $command->toArray();

// Get the 5 most recent activities.
$command = $hgc->getIterator('GetFitnessActivityFeed')->setLimit(5);
$result = $command->toArray();

$hgc = HealthGraphClient::factory();
$hgc->getUser(array(
    'access_token' => $token['access_token'],
    'token_type' => $token['token_type'],
));
$command = $hgc->getCommand('NewFitnessActivity', array(
    "type" => "Running",
    "start_time" => "Sat, 1 Jan 2011 00:00:00",
    "duration" => 600,
    "total_distance" => 1000,
    "notes" => "Ran 1000 meters in 600 seconds"
));
$result = $command->execute();
 bash
$ php composer.phar update