2012-04-21 68 views
2

我有Zend框架的问题。我试图从谷歌的服务器上删除单个联系人。我有类:Zend GData - 无法删除谷歌联系人 - Etag错误

class GContacts 
{ 
    const BASE_FEED_URI = 'https://www.google.com/m8/feeds'; 

    private $client = NULL; 
    private $gData = NULL; 
    private $contScope = ''; 
    private $groupScope = ''; 

    public function __construct($userName,$pass){  
     ini_set('include_path', LIB_DIR); 
     require_once('\Zend\Loader.php'); 

     Zend_Loader::loadClass('Zend_Gdata'); 
     Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 
     Zend_Loader::loadClass('Zend_Http_Client'); 
     Zend_Loader::loadClass('Zend_Gdata_Query'); 
     Zend_Loader::loadClass('Zend_Gdata_Feed');   

     $this -> client = Zend_Gdata_ClientLogin::getHttpClient($userName, $pass, 'cp'); 
     $this -> gData = new Zend_Gdata($this -> client); 
     $this -> gData -> setMajorProtocolVersion(3); 

     $this -> contScope = self :: BASE_FEED_URI . '/contacts/' . urlencode($userName); 
    } 

    public function addContact($cont){ 
     $doc = new DOMDocument(); 
     $doc -> formatOutput = true; 

     // header 
     $entry = $doc -> createElement('atom:entry'); 
     $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom'); 
     $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005'); 
     $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gContact', 'http://schemas.google.com/contact/2008'); 
     $doc -> appendChild($entry); 

     // add name element 
     $name = $doc -> createElement('gd:name'); 
     $entry -> appendChild($name); 
     $fullName = $doc -> createElement('gd:fullName', 'John Doe'); 
     $name -> appendChild($fullName); 

     // insert entry 
     $addResult = $this -> gData -> insertEntry($doc -> saveXML(), 'http://www.google.com/m8/feeds/contacts/default/full'); 

     return $this -> parseUniqueId($addResult -> id); 
    } 

    public function delete($gid){ 
     // Should be some work with Etag, but Zend is buggy and it doesn't work 
     $entry = $this -> gData -> getEntry($this -> contScope . '/full/' . $gid); 
     $entry -> delete(); 
    } 

    private function parseUniqueId($link){ 
     $arr = explode('/',$link); 
     return end($arr); 
    } 
} 

,并呼吁:

$gCont = new GContacts($userName,$pass); 

$gid = $gCont -> addContact('param will be soon'); 
$gCont -> delete($gid); 

这是问题所在(在删除方法):

  • 预期的响应码200,有403 IF-Match或如 - 无匹配头或条目etag属性要求

我必须使用谷歌Etag handling,因为有多个人可以访问此联系人,所以我不能在Zend bugreport中使用this或建议here。有谁想法如何解决它?

非常感谢! Ajax

编辑:这个错误不是固定的,在这里有人有这个问题吗?我很绝望.. :(

回答

0

我有解决方案。

有一个在Zend的\ GDATA \ App.php一个BUG

线547(在版本1.12.6),添加行$标题[ '如果 - 匹配'] = '*';在if条件现在,你应该有:

if ($method == 'DELETE') { 
    $rawData = null; 
    $headers['If-Match'] = '*'; 
} 

让我留在触摸;)

+0

您好!感谢您的回答。 Google联系人的这个项目已被跳过。刚才,我正在做一些完全不同的事情,我无法测试它。但是,谢谢你的回答,我确信我将在未来... – Ajax 2014-06-04 07:59:12