Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Last active August 29, 2015 14:00
Show Gist options
  • Save ezimuel/11373254 to your computer and use it in GitHub Desktop.
Save ezimuel/11373254 to your computer and use it in GitHub Desktop.
ZendOAuth example for Twitter
<?php
include '/path/to/vendor/autoload.php';
use ZendOAuth\Token\Access as AccessToken;
use Zend\Http\Request;
use Zend\Http\Response;
$config = array(
'callbackUrl' => 'http://example.com/callback.php',
'siteUrl' => 'http://twitter.com/oauth',
'consumerKey' => 'gg3DsFTW9OU9eWPnbuPzQ',
'consumerSecret' => 'tFB0fyWLSMf74lkEu9FTyoHXcazOWpbrAjTCCK48A'
);
$statusMessage = 'I\'m posting to Twitter using ZendOAuth!';
$token = new AccessToken();
$client = $token->getHttpClient($config);
$client->setUri('http://twitter.com/statuses/update.json');
$client->setMethod(Request::METHOD_POST);
$client->setParameterPost(array('status' => $statusMessage));
// SSL CA path for HTTPS used by Twitter
$adapter = $client->getAdapter();
$adapter->setOptions(array(
'sslcapath' => '/etc/ssl/certs'
));
$client->setAdapter($adapter);
$response = $client->send();
echo $response instanceof Response ? 'OK' : 'ERROR';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment