Created
May 29, 2010 20:21
-
-
Save abraham/418520 to your computer and use it in GitHub Desktop.
Simple PHP example of adding annotations to tweets using TwitterOAuth
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 | |
/** | |
* Note: Only select accounts have annotations enabled. | |
* | |
* If you have questions or comments please let me know. - @abraham | |
* | |
* Read about annotations: | |
* https://apiwiki.twitter.com/Annotations-Overview | |
* | |
* Get the TwitterOAuth source code: | |
* http://github.com/abraham/twitteroauth | |
* git clone [email protected]:abraham/twitteroauth.git | |
* | |
* Get your OAuth credentials: | |
* http://dev.twitter.com/pages/oauth_single_token | |
*/ | |
// Include TwitterOAuth library. | |
require_once('twitteroauth/twitteroauth.php'); | |
echo '<pre>'; | |
// Build a new connection object with consumer key/secret and users access token/secret. | |
$connection = new TwitterOAuth('consumer key', 'consumer secret', 'access token', 'access token secret'); | |
// Build annotations array. Notice the outer array. | |
$annotations = array(array('foo' => array('bar' => 'baz'))); | |
// POST new status with annotations json_encoded. | |
$result = $connection->post('statuses/update', array( 'status' => 'Hello annotated world!', | |
'annotations' => json_encode($annotations))); | |
// Check if the status POSTed correctly | |
if (200 == $connection->http_code) { | |
echo 'Success! :)'; | |
} else { | |
echo 'Failure! :('; | |
} | |
echo '<br><br>'; | |
// Print the successfully returned status or the error message. | |
print_r($result); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment