Skip to content

Instantly share code, notes, and snippets.

@abraham
Created May 29, 2010 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abraham/418520 to your computer and use it in GitHub Desktop.
Save abraham/418520 to your computer and use it in GitHub Desktop.
Simple PHP example of adding annotations to tweets using TwitterOAuth
<?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 git@github.com: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