15) ) ) )
die( "could not fetch $apiurl" );
// Check that JSON is well formed
$result = trim( $result );
if ( !$data = json_decode($result) )
die( "Data was not JSON" );
// Now extract a few variables from the $data object
$text = $data->text;
$created_at = date('d M Y g:i a', strtotime( $data->created_at ) );
if( !empty($data->source) )
$source = 'via '.$data->source;
if( !empty($data->in_reply_to_screen_name) ) {
$in_reply_to_screen_name = $data->in_reply_to_screen_name;
$in_reply_to_status_id = $data->in_reply_to_status_id;
$inreply = "in reply to @$in_reply_to_screen_name";
}
$name = $data->user->name;
$screen_name = $data->user->screen_name;
$profile_image = $data->user->profile_image_url;
// Make up some HTML with the tweet info
$html = <<
$text
$created_at $source $inreply
HTML;
// Put everything into a regular array
$json = array(
'version' => '1.0',
'type' => 'rich',
'width' => 1337, // this parameter is mandatory according to the oEmbed specs, but we're not using it
'height' => 1337, // same.
'html' => trim( $html ),
);
// Now output a JSON response
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
header('Content-Disposition: attachment; filename="oembed.json"');
echo json_encode( $json );
// The whole JSON response from Twitter API is something like:
/*
{ "contributors" : null,
"coordinates" : null,
"created_at" : "Mon Mar 26 19:23:40 +0000 2007",
"favorited" : false,
"geo" : null,
"id" : 13156561,
"in_reply_to_screen_name" : null,
"in_reply_to_status_id" : null,
"in_reply_to_user_id" : null,
"place" : null,
"source" : "txt",
"text" : "Testing phone update. I just dont get the point of this service...",
"truncated" : false,
"user" : { "contributors_enabled" : false,
"created_at" : "Mon Mar 26 19:17:04 +0000 2007",
"description" : "WordPress & PHP hacker.",
"favourites_count" : 15,
"followers_count" : 1384,
"following" : null,
"friends_count" : 92,
"geo_enabled" : true,
"id" : 2340481,
"lang" : "en",
"location" : "Nantes, France, Europe, World",
"name" : "Ozh Richard",
"notifications" : null,
"profile_background_color" : "ffffff",
"profile_background_image_url" : "http://a1.twimg.com/profile_background_images/49070346/thisisozh.png",
"profile_background_tile" : true,
"profile_image_url" : "http://a1.twimg.com/profile_images/30037632/ozh_normal.jpg",
"profile_link_color" : "100883",
"profile_sidebar_border_color" : "100883",
"profile_sidebar_fill_color" : "fff",
"profile_text_color" : "100883",
"protected" : false,
"screen_name" : "ozh",
"statuses_count" : 1290,
"time_zone" : "Paris",
"url" : "http://ozh.org/",
"utc_offset" : 3600,
"verified" : false
}
}
*/
}