【问题标题】:How can I use the Zend library, specifically the twitter class with codeigniter?如何使用 Zend 库,特别是带有 codeigniter 的 twitter 类?
【发布时间】:2011-08-03 02:25:27
【问题描述】:

我正在尝试在 codeigniter 中使用 Zend twitter 服务。

我已经用下面的方法集成了zendhttp://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/

我可以成功完成 Oauth 身份验证并从 twitter 接收有效的访问令牌,并且我的回调页面工作正常,但是当我尝试发出请求时,我收到以下错误:

Message: Undefined offset: 0

Filename: Client/Result.php

Line Number: 232

我正在像这样加载 twitter 类:

$this->load->library('zend');
$this->zend->load('Zend/Service/Twitter');

我不确定我是否应该加载其他内容,或者我做错了什么。

我正在使用 Codeigniter 2.0.2 和 ZendFramework 1.11.4

非常感谢任何帮助。

【问题讨论】:

  • 您能否发布更多代码来展示您如何使用 Twitter 服务?我假设只是加载类不是产生错误的原因?

标签: php zend-framework codeigniter twitter


【解决方案1】:

这个错误似乎与 CodeIgniter 和 Zend 没有直接关系。查看第 232 行的代码我可以看到这个

return (string) $result[0];

这是在以下函数中

/**
 * toString overload
 *
 * Be sure to only call this when the result is a single value!
 *
 * @return string
 */
public function __toString()
{
    if (!$this->getStatus()) {
        $message = $this->_sxml->xpath('//message');
        return (string) $message[0];
    } else {
        $result = $this->_sxml->xpath('//response');
        if (sizeof($result) > 1) {
            return (string) "An error occured.";
        } else {
            return (string) $result[0];
        }
    }
}

看来$result 不是一个数组——老实说,这似乎不是一个经过深思熟虑的函数。尝试查看有问题的课程 Zend/Rest/Client/Result.php,查看 $result 是什么以及对 Twitter 的调用是否真的成功。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多