Created
October 21, 2010 21:36
-
-
Save dcaunt/639409 to your computer and use it in GitHub Desktop.
auth.php gets a request token, redirects to twitter for user authentication
callback.php receives a callback from Twitter and saves the accessToken in the session
update.php sends a tweet using a raw OAuth HTTP client (and DOES work)
zst.php attempts t
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 | |
session_start(); | |
set_include_path('../library'); | |
require_once ('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
$config = array( | |
'callbackUrl' => 'http://' . $_SERVER['HTTP_HOST'] . '/callback.php', | |
'siteUrl' => 'http://twitter.com/oauth', | |
'consumerKey' => '5tsBnZBuuWP2FyqPlfDsVQ', | |
'consumerSecret' => '' | |
); | |
$consumer = new Zend_Oauth_Consumer($config); | |
$token = $consumer->getRequestToken(); | |
// persist the token to storage | |
$_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token); | |
// redirect the user | |
$consumer->redirect(); |
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 | |
session_start(); | |
set_include_path('../library'); | |
require_once ('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
$config = array( | |
'callbackUrl' => 'http://' . $_SERVER['HTTP_HOST'] . '/callback.php', | |
'siteUrl' => 'http://twitter.com/oauth', | |
'consumerKey' => '5tsBnZBuuWP2FyqPlfDsVQ', | |
'consumerSecret' => '' | |
); | |
$consumer = new Zend_Oauth_Consumer($config); | |
if (!empty($_GET) && isset($_SESSION['TWITTER_REQUEST_TOKEN'])) { | |
$token = $consumer->getAccessToken( | |
$_GET, | |
unserialize($_SESSION['TWITTER_REQUEST_TOKEN']) | |
); | |
$_SESSION['TWITTER_ACCESS_TOKEN'] = serialize($token); | |
// Now that we have an Access Token, we can discard the Request Token | |
$_SESSION['TWITTER_REQUEST_TOKEN'] = null; | |
} else { | |
// Mistaken request? Some malfeasant trying something? | |
exit('Invalid callback request. Oops. Sorry.'); | |
} |
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 | |
session_start(); | |
set_include_path('../library'); | |
require_once ('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
$config = array( | |
'callbackUrl' => 'http://' . $_SERVER['HTTP_HOST'] . '/callback.php', | |
'siteUrl' => 'http://twitter.com/oauth', | |
'consumerKey' => '5tsBnZBuuWP2FyqPlfDsVQ', | |
'consumerSecret' => '' | |
); | |
$statusMessage = !empty($_GET['msg']) ? $_GET['msg'] : 'I\'m posting to Twitter using Zend_Oauth!'; | |
$token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); | |
$client = $token->getHttpClient($config); | |
$client->setUri('http://twitter.com/statuses/update.json'); | |
$client->setMethod(Zend_Http_Client::POST); | |
$client->setParameterPost('status', $statusMessage); | |
$response = $client->request(); | |
$data = Zend_Json::decode($response->getBody()); | |
$result = $response->getBody(); | |
if (isset($data->text)) { | |
$result = 'true'; | |
} | |
echo $result; |
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 | |
session_start(); | |
set_include_path('../library'); | |
require_once ('Zend/Loader/Autoloader.php'); | |
Zend_Loader_Autoloader::getInstance(); | |
$token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); | |
Zend_Debug::dump($token); | |
$twitter = new Zend_Service_Twitter(array( | |
'username' => 'dcaunt', | |
'accessToken' => $token | |
)); | |
// verify user's credentials with Twitter | |
//$response = $twitter->account->verifyCredentials(); | |
$response = $twitter->status->update('MyGreatTweet'); | |
Zend_Debug::dump($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment