Amazon.com Widgets

Bible Verse Tweet

Bible Verse Tweet

Earlier this week I built a quick tool that automatically updates a Twitter account with a daily Bible verse from ESV.org (@TodaysVerse). The English Standard Version Bible has a really nice API that allows anyone to pull passages directly from their site. Likewise, Twitter has a very popular API that allows developers to build programs and scripts that can update a status and much more.

Since I'm a fan of open source solutions, I'm sharing this PHP script as an example of updating Twitter using PHP-Twitter with the Twitter API. Enjoy.

Step 1: Download PHP-Twitter - This is a single class file that is "installed" by copying the file 'class.twitter.php' to your web server.

Step 2: Copy the code below to a file that is in the same directory as the 'class.twitter.php' file.

Step 3: Read the documentation in the script below as an example of how to update your Twitter account with data from a source API or database.

Step 4: Add the PHP command line code #!/usr/local/bin/php.cli) to the very first line of your PHP script and then schedule the job to run nightly in CRON.

//This script will select a verse from the ESV Bible API
//and then post that verse on Twitter
//Author: @AdamParish

//Script requires the PHP-Twitter Class file
//http://code.google.com/p/php-twitter/
include_once('class.twitter.php');

//Create new instance of the twitter function
$t = new twitter();
$t->username='TwitterAccount';          
$t->password='TwitterPassword';

//Obtain a Bible Verse from the ESV Bible API
$key = "IP";
$format = "plain-text";
//$passage = urlencode("Psalm 46:3");
$options = "include-passage-references=true";
$options .= "&include-footnotes=false";
$options .= "&include-headings=false";
$options .= "&include-subheadings=false";
$options .= "&include-first-verse-numbers=false";
$options .= "&include-verse-numbers=false";
$options .= "&include-passage-horizontal-lines=false";
$options .= "&include-heading-horizontal-lines=false";
$options .= "&include-short-copyright=false";
//$url = "http://www.esvapi.org/v2/rest/passageQuery?key=$key&output-
format=$format&passage=$passage&$options"; $url = "http://www.esvapi.org/v2/rest/dailyVerse?
key=$key&output-format=$format&$options"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); //Updating Twitter with this verse $t->update($response); //Output repsonse to screen if ran manually print $response;

Just let me know if you have any questions or need help with this script.

Apr.23.2009.

This article hasn't been commented yet.

Write a comment

* = required field

:

:

:


7 + 1 =