/home/desid573/public_html/tollster
Edit: /home/desid573/public_html/tollster/playconsole.php (3081B)
setApplicationName('Google Calendar API PHP Quickstart');
$client->setScopes(Android_Publisher);
$client->setAuthConfig('client_secret.json');
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory('contactsCredentials.json');
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = "4/AADEQ3UpoPiXhDVlvPYYKcQWvYV4woaKZrEWqbSvNCMJCj0Ihnuh_n4";
//header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if (!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}
return $client;
}
/**
* Expands the home directory alias '~' to the full path.
* @param string $path the path to expand.
* @return string the expanded path.
*/
function expandHomeDirectory($path)
{
$homeDirectory = getenv('HOME');
if (empty($homeDirectory)) {
$homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH');
}
return str_replace('~', realpath($homeDirectory), $path);
}
// Get the API client and construct the service object.
function checkToken($product, $token) {
$client = getClient();
$accesstoken = $client->getAccessToken();
$accesstoken = $accesstoken['access_token'];
$url = "https://www.googleapis.com/androidpublisher/v3/applications/com.tollster.android/purchases/products/".$product."/tokens/".$token;
$curlObj = curl_init();
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: OAuth '.$accesstoken;
curl_setopt($curlObj, CURLOPT_URL, "$url");
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $headr);
curl_setopt($curlObj, CURLOPT_POST,true);
$response = curl_exec($curlObj);
curl_close($curlObj);
return $response;
}
?>