简体   繁体   English

Zend 1.12显示Twitter提要

[英]Zend 1.12 displaying a twitter feed

I am needing a twitter feed displayed in my zend website, just the feed, nothing else, so far everything I have tried either hasn't worked or has been unsuitable (for instance directly embedding the feed into the views html) 我需要在我的zend网站上显示一个Twitter提要,仅是提要,什么也没有,到目前为止,我尝试过的所有方法都行不通或不合适(例如,将提要直接嵌入到视图html中)

Currently I have a 'TwitterController.php' I have added a 'Twitter.php' script to the /zend/service/twitter/ folder as there wasn't one present and I have tried using the following code to no success 目前,我有一个'TwitterController.php',我已经向/ zend / service / twitter /文件夹中添加了一个'Twitter.php'脚本,因为目前没有一个脚本,并且我尝试使用以下代码未成功

$token = new Zend_Oauth_Token_Access();

        $token->setParams(array(
            'oauth_token'        => 'mytoken',
            'oauth_token_secret' => 'mytokensecret',
        ));

        $twitter = new Zend_Service_Twitter(array(
        'username'       => 'myname',
        'consumerKey'    => 'mykey',
        'consumerSecret' => 'mysecret',
        'accessToken'    => $token
        ));

The feed is to be displayed on my home page so I have tried this code in both IndexController and TwitterController. 该提要将显示在我的主页上,因此我在IndexController和TwitterController中都尝试了此代码。

This is surely easier than I have made it? 这肯定比我做的容易吗?

edit - I have added the following code to my IndexController and I have deleted the Twitter.php file, 'twas redundant. 编辑-我已将以下代码添加到我的IndexController中,并且删除了Twitter.php文件“冗余”。

// Create options array
        $options = array('accessToken' => $token);



// Request data from Twitter (20 most recent statuses posted from the authenticating user)
        $this->view->twitter_timeline = $twitter->status->userTimeline();

My view currently only has this piece of code in it: 我的视图当前仅包含以下代码:

<?php   $tweet = $this -> post -> text;?>

Which is throwing the error 哪个抛出错误

exception 'Zend_Service_Twitter_Exception' with message 'Invalid method type "status"'

It may also be worthy noting my twitter account currently only has 1 tweet? 还可能值得一提的是,我的Twitter帐户当前只有1条推文?

I think you need to tweak this slightly to: 我认为您需要对此进行一些微调以:

$twitter = new Zend_Service_Twitter(array(
    'username'       => 'myname',
    'accessToken'    => $token,
    'oauthOptions'   => array(
        'consumerKey'    => 'mykey',
        'consumerSecret' => 'mysecret',
    )
));

I'm slightly unsure what you mean your comment that you've added "a 'Twitter.php' script to the /zend/service/twitter/ folder" - you should never add files to the Zend folder, so if the above doesn't work perhaps you could explain what you mean by that a bit more. 我有点不确定您的意思是说您已在“ / zend / service / twitter /文件夹中添加了一个'Twitter.php'脚本”的评论-您绝对不应将文件添加到Zend文件夹中,因此如果上述内容没有可能行不通,也许您可​​以再解释一下您的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM