วันพฤหัสบดีที่ 18 พฤศจิกายน พ.ศ. 2553

program Auto post to Blogger with PHP



Auto post to Blogger with PHP
Similar to the way that plugins like wp-o-matic work for automatically posting rss feeds to Wordpress blogs, you can have a blogger blog which is automatically populated with RSS feed content, at intervals that you determine (by a cron job).
Blogger blogs allow the blogs owner to post via email, so we're going to use PHP's mail function to post new content, and PHP's SimpleXML to gather the content before posting.
Firstly, we need to set up our blogger blog to accept emailed posts: We need to go to our settings page in Blogger, and click the "Settings" tab at the top. Then click the "email" button.
You're now at the Email settings page, look for the Mail-to-Blogger Address. Here you just need to enter a password (in the box before the "@ablogger.com") that you'll use in your emails to post to the blogger blog.
Once you've chosen your password, write down the email address, as this is the email address we'll be using in the PHP script to tell it where to post the rss feed to.
Now on to the script:
//Your Blog's Keyword:
$keyword = "keyword";
//How many articles do you want to grab each time?
$num = 5;
//Get the RSS Feed - In this instance, we're using a google blogsearch feed based on our chosen keyword
$feed = simplexml_load_file("http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&q=" .urlencode($keyword). "&ie=utf-8&num=10&output=rss");
//Loop through our keywords
foreach ($feed->channel->item as $item) {
if($i < $num){
//Have a bit of a rest so we're not posting too fast to our blogger blog
sleep(10);
$title = $item->title;
$title = str_replace("", "", $title);
$subject = str_replace("
", "", $title);
$link = $item->link;
$description = $item->description;
$description = str_replace("", "", $description);
$body = str_replace("
", "", $description);
//put our secret blogger email address here:
$to = "accountname.password@blogger.com";
//ignore this line - the script just needs something in the "From" field.
$headers = 'From: mail@whatever.com';
//Send the email / How'd we go?
if(mail($to, $subject, $body, $headers)) {
echo $subject. " - sent
";
}
else
{
echo $subject. " - NOT sent
";
}
}
//add one to our counter
$i++;
}
?>


Read more: http://www.bukisa.com/articles/310946_auto-post-to-blogger-with-php#comment-108123#ixzz148tVvM8R
by service

ไม่มีความคิดเห็น:

แสดงความคิดเห็น