2

Zend 框架有问题。我正在尝试从谷歌服务器中删除单个联系人。我有课:

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 或 If-None-Match 标头或需要条目 etag 属性

我必须使用 google Etag 处理,因为有不止一个人可以访问这个联系人,所以我不能在 Zend 错误报告中使用这个建议。有谁知道如何解决它?

非常感谢!阿贾克斯

编辑:这个错误根本没有修复,这里有人有这个问题吗?我很绝望.. :(

4

1 回答 1

0

我有解决办法。

Zend\Gdata\App.php 有BUG

第 547 行(版本 1.12.6),添加行$headers['If-Match'] = '*'; 在 if 条件下。现在,你应该有:

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

保持联系;)

于 2014-06-03T18:22:39.430 回答