I was using basic auth to send tweets from a server every time a song changed. Now they have blocked basic auth and I am not sure how to incorporate it. I have a server at home that updates an html file on the webserver and then calls the following script to tweet out from that file. Any ideas on how to accomplish this simply?
<?php
//==================================================== // CONFIGURATION //====================================================
// YOUR TWITTER USERNAME AND PASSWORD $username = '#####'; $password = '#####';
DEFINE(htmlfile, '/homec/public_html/site.com/twitter.html');
$stationURL = "http://www.site.com";
$maxLimit = "139";
$da=""; $f=@fopen(htmlfile, "r");
if ($f!=0) { $da=@fread($f, 4096); fclose($f); } else { exit; }
$da=str_replace("\r", "\n", $da); $da=str_replace("\n\n", "\n", $da); $d=explode("\n", $da);
$d[0]=trim($d[0], "|"); // title $d[1]=trim($d[1], "|"); // artist
//==================================================== if ($d[0]=="" || $d[1]=="") { // IF WE COULD NOT GRAB THE ARTIST AND // SONG TITLE FROM THE SAM-GENERATED HTML FILE, // WE'LL BAIL OUT NOW WITHOUT SUBMITTING ANY TEXT // TO TWITTER. exit; } else { // SUCCESS IN GETTING ARTIST AND TITLE! // WE'LL PROCEED WITH BUILDING A TEXT STRING TO SUBMIT TO TWITTER.
$message = urlencode('' . $d[1] . ' - ' . $d[0] . ' #bandradio #nowplaying ');
$stationURL = urlencode(' ' . $stationURL);
if ((strlen($message) + strlen($stationURL)) > $maxLimit) { // We have to truncate the artist-title string to make room for the station URL string. $message = substr($message, 0, (($maxLimit - 2) - strlen($stationURL))); $message .= ".." . $stationURL; } else { // No need to truncate, it all fits. $message = $message . $stationURL; } } // if ($d[0]=="" || $d[1]=="")
//==================================================== // The twitter API address $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); //curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message"); //curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); $buffer = curl_exec($curl_handle); $resultArray = curl_getinfo($curl_handle); curl_close($curl_handle);