Jump to content

[SOLVED] anybody worked with twitter api?


dadamssg

Recommended Posts

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, 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.

 

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. but on those "A" ones that don't show up on my twitter account, they also get updated for some reason.

 

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;



?>

Link to comment
Share on other sites

i did this

 

$agurl = " http://www.mysite.com/beta/showevent1.php?id={$list['eventid']}";

$id = $list['eventid'];

$title = stripslashes($list['title']);

$tweet = $title." ".$agurl;
$twitter = htmlentities($tweet);

 

but the same result...i just end up with a freakin "A".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.