views:

69

answers:

3

I am unable to tweet continuously in twitter - every three tweets I get:

Error posting to Twitter. Retry

How do I fix this?

My code is as follows:

$host = "http://twitter.com/statuses/update.xmlstatus=".urlencode(stripslashes(urldecode($message)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
$result = curl_exec($ch);
// Look at the returned header
$resultArray = curl_getinfo($ch);
//print_r($resultArray);
if($resultArray['http_code'] == "200"){
     $twitter_status='Your message has been Tweeted';
     update_tweet_extra($result_id,"1");
} else {
 $twitter_status="Error posting to Twitter. Retry";
 // update_tweet_extra($result_id,"0");
}
echo  $twitter_status;
+1  A: 

This seems very odd, since status updates via the Twitter API are not rate-limited (see here), unless you're updating more than 1000 times a day.

You might work out more of what happened if you uncomment that helpful looking line:

//print_r($resultArray);

by removing the // at the beginning of line.

Dominic Rodger
This should be a comment
Jan Jongboom
@Jan - it is. Or were you referring to my answer?
Dominic Rodger
is it necessary , i should remove the comments
Bharanikumar
its ok i removed that comment line also, bxoz i want to fix my problem....
Bharanikumar
If you remove the `//` which makes that line a comment, you may find information that will help you figure out what's gone wrong.
Dominic Rodger
Sorry man , i know // not make much work in the functionality , but the thing am struggling with tweets, am getting Error only after 5 tweets , then as usual working fine, so if snippet is wrong , then we debug the code, but the thing Error occuring some time only.
Bharanikumar
+2  A: 

I don't think this is a problem with your code, but more the fact that Twitter is phasing out basic authentication support and moving to OAuth.

There's more information at http://apiwiki.twitter.com/Authentication.

Martin Bean
i looked this oAuth , i thing there no simple example to test oAuth.
Bharanikumar
sure there is: http://dev.twitter.com/
Jayrox
More specifically, take a look at: http://dev.twitter.com/pages/auth
Martin Bean
+1  A: 

You can't use API with basic authentication since 31 august 2010. You can use a small spider function with curl that login in, fetch your home, and tweet. I made it: http://www.barattalo.it/2010/09/09/how-to-change-twitter-status-with-php-and-curl-without-oauth/ If you don't want to use oAuth authentication model you have to do this way.

Pons
in my localhost working fine , but i pur this cod ein my server , my tweets not displaying in my twitter,
Bharanikumar