<? function setupClient($singleUseToken = null) { $client = null; // Fetch a new AuthSub token? if (!$singleUseToken) { $next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $scope = 'https://www.google.com/health/feeds'; $authSubHandler = 'https://www.google.com/health/authsub'; $secure = 1; $session = 1; $permission = 1; // 1 - allows posting notices && allows reading profile data $authSubURL = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session, $authSubHandler); $authSubURL .= '&permission=' . $permission; echo '<a href="' . $authSubURL . '">Link your Google Health Account</a>'; } else { $client = new Zend_Gdata_HttpClient(); // This sets your private key to be used to sign subsequent requests $client->setAuthSubPrivateKeyFile('/path/to/myrsakey.pem', null, true); $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken(trim($singleUseToken), $client); // Set the long-lived session token for subsequent requests $client->setAuthSubToken($sessionToken); } return $client; } ?>Use this function like this:
$client = setupClient(@$_GET['token']); if ($client) { // Query a feed } else { exit(); // Just display the AuthSub link }
Update:Read the new documentation on using AuthSub for PHP as well as all the other client libraries.