Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

Zend_Client_Twitter with OAuth and a single access token

by Pascal Opitz on September 26 2010, 16:26

Just noticed that twitter switched their API to OAuth only, which broke our blog updates on twitter. Here's a hotfix to use the single access token provided by Twitter.

Config

Of course you'll have to get the right data from dev.twitter.com.


twitter.user = "myusername"
twitter.consumer_key = "xxxxxx"
twitter.consumer_secret = "yyyyyy"
twitter.access_token = "XXXXXX"
twitter.access_secret = "YYYYYY"

Code


$message = "my update";

$token = new Zend_Oauth_Token_Access();
$token->setToken($this->config->twitter->access_token);
$token->setTokenSecret($this->config->twitter->access_secret);

$twitter_client = $token->getHttpClient(array(
    'callbackUrl' => 'http://example.com/callback.php',
    'siteUrl' => 'http://twitter.com/oauth',
    'consumerKey' => $this->config->twitter->consumer_key,
    'consumerSecret' => $this->config->twitter->consumer_secret,
));

$twitter = new Zend_Service_Twitter(array(
    'username' => $this->config->twitter->user,
    'accessToken' => $token,
));

$twitter->setLocalHttpClient($twitter_client);
$response = $twitter->account->verifyCredentials();
$twitter->status->update($message);

Comments

Don't miss the opportunity to leave the first comment.

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement