Learn how you can boost your content marketing efforts by automatically sharing posts to Twitter from a CSV or Google Spreadsheet at regular intervals.
“Evergreen content” is owned or earned media which is still relevant and of interest to your target audience weeks, months or even years after publication.
The value of evergreen content is that it can continue to deliver traffic, leads, conversions and social shares and can occupy valuable positions in search-engine results pages for a prolonged period of time after initial creation & publication.
Using evergreen should can be a valuable part of a comprehensive content marketing strategy, and it becomes even more valuable when combined with SEO techniques. (Consider basing your evergreen pieces around keywords you’d like your site to rank for)
Setting things up is easy, but you before you start you need
Read our guide to setting up a Twitter app.
URL,Description
Now add some data rows (Tweet text and links to posts you want to automatically broadcast on Twitter), as well as any required URL tracking parameters
//Post to Twitter from a Local CSV File at specific time intervals
//(c) 2017 - https://Marketinghacker.blog - Twitter @marketinghack3r
//file: index.php
$cwd = getcwd();
$bEnableLogging = true;
require_once($cwd.'/twitteroauth-master/autoload.php');
use Abraham\TwitterOAuth\TwitterOAuth;
global $connection;
$inputfile = $cwd.'/myevergreencontent.csv';
$connection = new TwitterOAuth($CONSUMER_KEY="INSERT-CONSUMER-KEY-HERE",
$CONSUMER_SECRET="INSERT-CONSUMER-SECRET-KEY-HERE",
$access_token="INSERT-ACCESS-TOKEN-HERE",
$access_token_secret="INSERT-ACCESS-TOKEN-SERET-HERE");
shareFromCSV();
//====================================================================================================================================
function shareFromCSV()
{
global $inputfile, $connection;
$theData = readCSV($inputfile);
$numrows = sizeof($theData);
if ($numrows >0)
{
$index = rand(0, sizeof($theData)-1);
$status = $connection->post("statuses/update", ["status" => $theData[$index]['Description'].' '.$theData[$index]['URL']]);
if($bEnableLogging)
{
$status_txt='';
if ($connection->getLastHttpCode() == 200){
$status_txt= 'Posted tweet id:'.$status->id_str.' at '.$status->created_at.' - text: '.$status->text;
}
else
$status_txt='Error Posting Tweet: '.$theData[$index]['Description'].' '.$theData[$index]['URL'];
file_put_contents('log.txt', $status_txt.PHP_EOL , FILE_APPEND | LOCK_EX);
}
}
}
//====================================================================================================================================
function readCSV($csvFile)
{
$aryData = array();
$header = NULL;
$handle = fopen($csvFile, "r");
if($handle)
{
while (!feof($handle) )
{
$aryCsvData = fgetcsv($handle);
if(!is_array($aryCsvData))
{
continue;
}
if(is_null($header))
{
$header = $aryCsvData;
}
elseif (is_array($header) && count($header) == count($aryCsvData))
{
$aryData[] = array_combine($header, $aryCsvData);
}
}
fclose($handle);
}
return $aryData;
}
//====================================================================================================================================
//Via https://Marketinghacker.blog
The Cronmaker is a useful tool for generating the correct ‘cron Expression’ string.
Visiting the cronmaker site, we selected ‘every weekday’ at 11:00 and we clicked ‘Generate Cron Expression’.
Resulting in the following output:
0 0 11 1/1 * ? *
In your hosting Control panel find the CRON settings and add a new entry like this (replacing the part before the ‘wget’ below with the cron string you created on cronmaker, and your own domain name)
0 0 11 1/1 * ? * wget -O - https://yoursite.com/evergreen-scheduler/index.php >/dev/null 2>&1
(Tech Note: Using -O means that the output of the web request will be sent to STDOUT (standard output), by adding >/dev/null we instruct standard output to be redirect to a black hole. by adding 2>&1 we instruct STDERR (errors) to also be sent to STDOUT, and thus all output will be sent to a blackhole. (so it will load the website, but never write a file anywhere).
Congratulations – you have just created a Twitter APP, built a 100% free Evergreen content broadcast tool for Twitter, and mastered the art of the CRON job.
Automation is awesome. evergreen content is awesome, and YOU are awesome.