Need to urlencode() the tweets.. the & is screwing it up for you.

-Chad

On Sat, Jun 27, 2009 at 5:43 PM, david<[email protected]> wrote:
>
> Im having trouble writing a script that tweets the title and urls of
> events getting posted. I go to texas a&M and am trying to tweet the
> games and other events, so my literal tweet is
>
> A&M vs tu Football Game http://www.mysite.com/beta/showevent1.php?id=482
>
> but it only tweets "A"...thats it OR it doesn't show up. The first one
> that gets tweeted with A&M at the start shows up as A, but then if the
> very next one that starts with A&M won't show up at all.
>
> but if the tweet doesn't start with "A&M", say the tweet is
>
> Blaggards Concert http://www.mysite.com/beta/showevent1.php?id=483
>
> then it works perfect. Tweets every time. I'm also checking to see if
> the curl is successful....if it is-->update my tweet column to show
> that it has been tweeted. The ones that start with A&M that come after
> the "A" tweet don't show up on the twitter account, but DO get
> updated.
>
> heres my script
>
>
> <?php
> include("caneck.inc");
>
> $cxn = mysqli_connect($host,$user,$passwd,$dbname)
>          or die ("Couldn't connect");
>
> //grab the first event that hasn't been tweeted
>  $sql = "SELECT * FROM `test` WHERE tweet = '0' limit 1";
>   $result = mysqli_query($cxn,$sql)
>             or die (mysqli_error($result));
>
>
>   $list = mysqli_fetch_assoc($result);
>
> $agurl = " http://www.mysite.com/beta/showevent1.php?id={$list['eventid']}";
>
> $id = $list['eventid'];
>
> $title = stripslashes($list['title']);
>
> $tweet = $title." ".$agurl;
>
> $username = 'myusername';
> $password = 'mypassword';
> // The message you want to send
> // The twitter API address
> //$urlb = 'http://twitter.com/statuses/update.xml';
> // Alternative JSON version
> $urlb = 'http://twitter.com/statuses/update.json';
> // Set up and execute the curl process
> $curl_handle = curl_init();
> curl_setopt($curl_handle, CURLOPT_URL, "$urlb");
> 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=$tweet");
> curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
>
> //if tweet is successful, update row to reflect that
> if(curl_exec($curl_handle))
> {
> $sqr = "Update test SET tweet = '1' WHERE eventid = $id";
> $res = mysqli_query($cxn,$sqr)
>             or die (mysqli_error($res));
> }
> else
> {
>
> }
>
>
> curl_close($curl_handle);
>
> echo $title;
> echo $agurl;
>
> echo "<br><br>";
>
> echo $tweet;
> ?>
>
> So my twitter account ends up looking like so after a few tweets
>
> inaggietest Johnny Cooper Band http://bit.ly/1f3Go
> 26 minutes ago from web
>
> inaggietest A
> 27 minutes ago from web
>
> inaggietest Aaron Watson http://bit.ly/xCpR
> 28 minutes ago from web
>
>
> inaggietest A
> 29 minutes ago from web
>
>
> inaggietest College Station Knitting Meetup http://bit.ly/vbHr
> 30 minutes ago from web
>
>
> inaggietest JEFF DUNHAM @ FIRST YELL http://bit.ly/fagF
>

Reply via email to