Google Calendar sangat memudahkan programer web untuk berinteraksi dengan kalender ybs.
Kita bisa menggunakan teknik sederhana seperti melakukan embedding kalender ini pada situs Web Pribadi kita.Kita juga bisa berinteraksi pada tingkatan lebih menggunakan PHP dan API Google.
Panduan sbb bisa membantu:
https://developers.google.com/google-apps/calendar/quickstart/php
Langkah pertama dapatkan api nya berupa .json
download :
{"web":{"client_id":"63381824239-gvdiqjmvg3plualpjhus26he52dlhhbp.apps.googleusercontent.com","project_id":"api-project-216338182423912","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"93DCUfmk_1T-2YjqHztShtCe"}}
ubah namanya menjadi client_secret.json
Gunakan komposser u instal:
Panduan versis Zend Framework:
http://segiempat.com/tips-dan-cara/teknologi/blog/bagaimana-cara-mengakses-google-calendar-dengan-php-dan-api-google/
Kita bisa menggunakan teknik sederhana seperti melakukan embedding kalender ini pada situs Web Pribadi kita.Kita juga bisa berinteraksi pada tingkatan lebih menggunakan PHP dan API Google.
Panduan sbb bisa membantu:
https://developers.google.com/google-apps/calendar/quickstart/php
Langkah pertama dapatkan api nya berupa .json
download :
{"web":{"client_id":"63381824239-gvdiqjmvg3plualpjhus26he52dlhhbp.apps.googleusercontent.com","project_id":"api-project-216338182423912","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"93DCUfmk_1T-2YjqHztShtCe"}}
ubah namanya menjadi client_secret.json
Gunakan komposser u instal:
php composer.phar require google/apiclient:^2.0
buat kode contoh.php:
<?php
require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Google Calendar API PHP Quickstart');
define('CREDENTIALS_PATH', '~/.credentials/calendar-php-quickstart.json');
define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/calendar-php-quickstart.json
define('SCOPES', implode(' ', array(
Google_Service_Calendar::CALENDAR_READONLY)
));
if (php_sapi_name() != 'cli') {
throw new Exception('This application must be run on the command line.');
}
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
function getClient() {
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setAuthConfig(CLIENT_SECRET_PATH);
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
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 = trim(fgets(STDIN));
// 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.
$client = getClient();
$service = new Google_Service_Calendar($client);
// Print the next 10 events on the user's calendar.
$calendarId = 'primary';
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
if (count($results->getItems()) == 0) {
print "No upcoming events found.\n";
} else {
print "Upcoming events:\n";
foreach ($results->getItems() as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s (%s)\n", $event->getSummary(), $start);
}
}
Jalankan::
php contoh.php
Panduan versis Zend Framework:
http://segiempat.com/tips-dan-cara/teknologi/blog/bagaimana-cara-mengakses-google-calendar-dengan-php-dan-api-google/


Komentar
Posting Komentar