Exemplo n.º 1
0
$redirect_url = 'http://localhost/healthgraph/';
if (isset($_GET['code'])) {
    // user accepted access
    $token = Authorization::authorize($_GET['code'], $client_id, $client_secret, $redirect_url);
    if ($token) {
        $_SESSION['token'] = $token;
    }
    header("Location: {$redirect_url}");
} elseif (isset($_GET['error'])) {
    // user denied access
    $button = Authorization::getAuthorizationButton($client_id, $redirect_url);
    echo $button['html'];
    echo '<h2>Denied</h2>';
} elseif (isset($_GET['revoke'])) {
    // user wants to disconnect
    $auth = new Authorization();
    if ($auth->deauthorize($token['access_token'])) {
        unset($_SESSION['token']);
    }
    header("Location: {$redirect_url}");
} elseif (!isset($token)) {
    // user is not connected
    $button = Authorization::getAuthorizationButton($client_id, $redirect_url);
    echo $button['html'];
} else {
    // user is already connected
    echo "<a href='{$redirect_url}?revoke'>Disconnect</a>";
    $hgc = Client::factory(array('access_token' => $token['access_token'], 'token_type' => $token['token_type']));
    try {
        $profile = $hgc->getProfile()->getAll();
        var_dump($profile);
Exemplo n.º 2
0
 /**
  * @covers HealthGraph\Authorization::deauthorize
  * @todo   Implement better testDeauthorize().
  */
 public function testDeauthorize()
 {
     $auth = new Authorization();
     $result = $auth->deauthorize($this->authorization_code);
     $this->assertTrue($result);
 }
Exemplo n.º 3
0
 * [$redirect_url app location]
 * @var string
 */
$client_id = 'YOUR_CLIENT_ID';
$client_secret = 'YOUR_CLIENT_SECRET';
$redirect_url = 'http://localhost/runkeeper_mass_import';
/**
 * [$button Runkeeper connect button]
 * @var [type]
 */
$button = Authorization::getAuthorizationButton($client_id, $redirect_url);
// Spit connect button to the page
echo $button['html'];
// the healthgraph api returns ?code=xxxx on success...I havent confirmed this but it should be on success
if (isset($_REQUEST['code'])) {
    $token = Authorization::authorize($_GET['code'], $client_id, $client_secret, $redirect_url);
    $hgc = HealthGraphClient::factory();
    $hgc->getUser(array('access_token' => $token['access_token'], 'token_type' => $token['token_type']));
    // Scan all files in the data folder excluding .DS_Store
    // TODO: Check if valid GPX file. There is no error handling for that yet
    $dir = getcwd() . '/data/';
    $files = scandir($dir);
    $files = array_diff($files, array('.', '..', '.DS_Store'));
    $gpxCount = 0;
    $gpxData = array();
    foreach ($files as $file) {
        $xml = simplexml_load_file($dir . $file);
        $track = array();
        $count = 0;
        // Dump track data to an array
        foreach ($xml->trk->trkseg->trkpt as $trackInfo) {