Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Framework: Zend_Oauth and Zend_Service_Twitter
    primarykey
    data
    text
    <p>First of all, I am able to successfully authenticate using Oauth. I am using Padraic's tutorial found here: <a href="http://blog.astrumfutura.com/archives/411-Writing-A-Simple-Twitter-Client-Using-the-PHP-Zend-Frameworks-OAuth-Library-Zend_Oauth.html" rel="nofollow noreferrer">http://blog.astrumfutura.com/archives/411-Writing-A-Simple-Twitter-Client-Using-the-PHP-Zend-Frameworks-OAuth-Library-Zend_Oauth.html</a></p> <p>Now, my problem is that I already have a Twitter model using Zend_Service_Twitter. But since Zend_Service_Twitter requires a password, I decide to extend it. My new class is like this:</p> <pre><code>&lt;?php /** * I'm trying to extend Zend_Service_Twitter to use Oauth instead */ require_once 'Zend/Service/Twitter.php'; class Mytwitterapp_Twitteroauth extends Zend_Service_Twitter { /** * Oauth * @var Zend_Oauth_Token_Access */ protected $_token; /** * Array for Zend_Oauth_Consumer (i think) * @var Zend_Config_Ini */ protected $_config; /** * @param object $token * @return void */ public function __construct(Zend_Oauth_Token_Access $token) { $this-&gt;_config = new Zend_Config_Ini(APPLICATION_INI, APPLICATION_ENV); $this-&gt;_token = $token; $this-&gt;setUri('http://twitter.com'); $client = $this-&gt;_token-&gt;getHttpClient($this-&gt;_config-&gt;oauth-&gt;toArray()); } public function _init() { $client = $this-&gt;_token-&gt;getHttpClient($this-&gt;_config-&gt;oauth-&gt;toArray()); } } </code></pre> <p>And so my Model_Twitter, looks something like this:</p> <pre><code>&lt;?php require_once 'Mytwitterapp/Twitteroauth.php'; class Twitter_Model_Twitter { private $_twitter; private $_username; private $_password; public function __construct(array $options = null) { $oauth = new Zend_Session_Namespace('Twitter_Oauth'); $token = unserialize($oauth-&gt;twitter_access_token); $this-&gt;_twitter = new Mytwitterapp_Twitteroauth($token); } public function setOptions(array $options) { $methods = get_class_methods($this); foreach ($options as $key =&gt; $value) { $pieces = explode('_', $key); foreach($pieces AS $piece_key =&gt; $piece_value) { $pieces[$piece_key] = ucfirst($piece_value); } $name = implode('',$pieces); $method = 'set' . $name; if (in_array($method, $methods)) { $this-&gt;$method($value); } } return $this; } public function setTwitter($obj) { $this-&gt;_twitter = $obj; return $this; } public function verifyCredentials() { return $this-&gt;_twitter-&gt;account-&gt;verifyCredentials(); } public function userTimeline() { return $this-&gt;_twitter-&gt;status-&gt;userTimeline(); } //...more code here... } </code></pre> <p>And so finally, I am expecting to use these with something like this:</p> <pre><code>$twitter_model = new Twitter_Model_Twitter(); $this-&gt;view-&gt;friendsTimeline = $twitter_model-&gt;friendsTimeline(); </code></pre> <ol> <li><p><strong>Am I doing it right? (In terms of extending my Zend_Service_Twitter class).</strong></p></li> <li><p><strong>How would you implement something like this?</strong></p></li> </ol> <p>I also get this error: </p> <pre><code>Zend_Rest_Client_Result_Exception: REST Response Error: fopen(/htdocs/twitter/application/views/helpers/Layout.php) [function.fopen]: failed to open stream: No such file or directory in /Applications/MAMP/bin/php5/lib/php/Zend/Rest/Client/Result.php on line 67 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload