The Quickest Way To Tweet via Zend Framework’s Twitter Service

This is a quick and dirty method.  It assumes a couple of things.

  1. You’ve already created your ‘app’ on twitter.
  2. You’ve already gotten your personal OAuth tokens from twitter.

First you need to setup your tokens;

$token = new Zend_Oauth_Token_Access();
$token->setToken("YOUR_PERSONAL_TOKEN")
      ->setTokenSecret("YOUR_PERSONAL_SECRET");

Second, you need to setup the Zend_Service_Twitter using your access token as well as the application tokens provided by twitter.

$options = array(
 'accessToken'    => $token,
 'callbackUrl'    => 'http://' .$_SERVER['HTTP_HOST']. '/',
 'consumerKey'    => "YOUR_APPLICATION_KEY",
 'consumerSecret' => "YOUR_APPLICATION_SECRET");

 $twitter = new Zend_Service_Twitter($options);
 $response = $twitter->status->update($message);

And that’s it.

If you want to do other things like authenticate multiple users, you’ll have to do a few other steps. Twitter was nice enough to make it “easy” for a single user to create their own app and post without any goofy intermediate authentication steps.

Published by Darryl Clarke

random text goes here, i guess