2011-03-20 83 views
1

谷歌已經用他們的日曆API找到了一些東西,現在我需要修復一些將自己添加到文本中的奇怪符號。我發現這個線程這正好說明我處理這個問題: http://www.google.com/support/forum/p/Calendar/thread?tid=25ac3d762b235a51&hl=en如何將querystring追加到對象?

解決的辦法是追加「& HL = en」或「HL =恩?」我的「基本」 URL加料結束。

我confunsed如何做到這一點,雖然,因爲我檢索飼料與Zend_Gdata對象:

<?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 = "xxxxx"; 
$pass = "xxxxx"; 
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); 
$gcal = new Zend_Gdata_Calendar($client); 

$query = $gcal->newEventQuery(); 
$query->setUser('[email protected]'); 
$secondary=true; 
$query->setVisibility('private'); 
$query->setProjection('basic'); 
$query->setOrderby('starttime'); 
$query->setSortOrder('ascending'); 
//$query->setFutureevents('true'); 

$startDate=date('Y-m-d h:i:s'); 
$endDate="2015-12-31"; 
$query->setStartMin($startDate); 
$query->setStartMax($endDate); 
$query->setMaxResults(30); 
try { 
    $feed = $gcal->getCalendarEventFeed($query); 
} catch (Zend_Gdata_App_Exception $e) { 
    echo "Error: " . $e->getResponse(); 
} 

?> 

我試過,沒有運氣做到這一點:

$query->setProjection('basic?hl=en'); 

回答

1

注:我以前沒有使用過任何這個,所以我很抱歉,如果這不起作用:)

documentationgetCalendarEventFeed()可以將URL作爲參數。 因此,我們可以爲了改變這種...

$feed = $gcal->getCalendarEventFeed($query); 

...這將參數添加到查詢字符串:

$eventUrl = $query->getQueryUrl() . '?hl=en'; 
$feed = $gcal->getCalendarEventFeed($eventUrl); 

顯然,這是一個簡單的例子 - 你還是應該執行以下兩項檢查:

  1. 調用它getQueryUrl()之前,確保$queryZend_Gdata_Query一個實例。

  2. 確保沒有其他查詢參數已添加到$eventUrl,以便我們可以使用&hl=en而不是?hl=en。你可以使用Zend_Uri

+0

嘿,夥計,那工作!非常感謝! – Joel 2011-03-20 07:23:16