2011-03-20 82 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