<?php require_once("codebird.php"); // reference the codebird php library file (downloaded in step one above) class BlogPost{ var $date; var $ts; var $link; var $title; var $text; } class BlogFeed{ var $posts = array(); function __construct($file_or_url) { $file_or_url = $this->resolveFile($file_or_url); if (!($x = simplexml_load_file($file_or_url))) { return; } foreach ($x->channel->item as $item) { $post = new BlogPost(); $post->date = (string) $item->pubDate; $post->ts = strtotime($item->pubDate); $post->link = (string) $item->link; $post->title = (string) $item->title; $post->text = ""; // not using this for tweets $this->posts[] = $post; } } private function resolveFile($file_or_url) { if (!preg_match('|^https?:|', $file_or_url)) $feed_uri = $file_or_url; else $feed_uri = $file_or_url; return $feed_uri; } private function summarizeText($summary) { $summary = strip_tags($summary); // Truncate summary line to 100 characters $max_len = 100; if (strlen($summary) > $max_len) $summary = substr($summary, 0, $max_len) . '...'; return $summary; } } // read in posts $ps = new BlogFeed("http://www.dailymotion.com/rss/user/[daily motion user name]"); // your dailymotion rss feed (step three above) $posts = $ps->posts; $c=count($posts); $r=rand(1,$c); $r=$r-1; $p=$posts[$r]; $link=$p->link; $title=$p->title; if($link!="") { $message = $title." ".$link; // note that the twitter 140 character limit applies to the total of message sent // now tweet - [] key information unique to twitter account - obtain keys via https://apps.twitter.com/app/new (step two above) \Codebird\Codebird::setConsumerKey('[YOURKEY]', '[YOURSECRET]'); $cb = \Codebird\Codebird::getInstance(); $cb->setToken("[YOURTOKEN]", "[YOURTOKENSECRET]"); $params = array( 'status' => $message ); $reply = $cb->statuses_update($params); // display message to screen echo($message); } ?>Note: disclaimers on code/snippet usage applies – no responsibility on usage. Check My Tool: https://dailymotiontop.tk/submit-twitter/
Subscribe
0 Bình luận
Cũ nhất