Last active
August 29, 2015 14:00
-
-
Save ezimuel/11373254 to your computer and use it in GitHub Desktop.
ZendOAuth example for Twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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