您必須確保用戶已經共享日曆或將其公開。 Google正在努力加強他們的安全。您使用的方法允許您訪問用戶的私人日曆。這顯然是不受歡迎的行爲。 Google數據協議api支持多種身份驗證方法。該分類HERE旨在幫助您選擇哪一種適合您的應用。 api文檔建議使用oauth進行身份驗證,並且網站http://oauth.net/提供了幾個用於從PHP訪問API的庫。 OpenID也是一個受支持的選項,也是一種混合體,它旨在通過利用OAuth和OpenID來簡化流程。
只要在IFrame中顯示日曆,只需創建一個HTML頁面,爲您的日曆檢索atom feed並將事件顯示爲html。因爲它是XML,所以您喜歡的任何XML處理方法都可以使用(即XSLT,simpleXML等)。然後使用此頁面的url作爲iframe的源屬性。
下面是使用Zend GATA庫的例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Example List of calendar contents</title>
</head>
<body>
<?php
// load library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// create authenticated HTTP client for Calendar service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "[email protected]";
$pass = "pass";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
// generate query to get event list
$query = $gcal->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('basic');
// get and parse calendar feed
// print output
try { $feed = $gcal->getCalendarEventFeed($query); }
catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getResponse(); }
?>
<h1><?php echo $feed->title; ?></h1>
<p><?php echo $feed->totalResults; ?> event(s) found.<p/>
<ol>
<?php
foreach ($feed as $event)
{
echo "<li>\n";
echo "<h2>" . stripslashes($event->title) . "</h2>\n";
echo stripslashes($event->summary) . " <br/>\n";
echo "</li>\n";
}
echo "</ul>";
?>
</ol>
</body>
</html>
此文件的網址是iframe的來源。
祝你好運,快樂的編碼。
上帝的緣故ppl。它是Zend Framework,Zend是一家公司。 – markus