Sometimes tweets are not made

12 views
Skip to first unread message

krumlr

unread,
Dec 23, 2008, 6:03:38 PM12/23/08
to Twitter Development Talk
I am using curl to send tweets and sometimes they don't go through yet
I do not get an error message. The section of curl that should take
care of this is

/* Execute and get the http code to see if it was succesfull or not*/
$result = curl_exec($this->ch);
$resultArray = curl_getinfo($this->ch);

if ($resultArray['http_code'] == 200) ;
return true;

any ideas why this is not working?

Thanks
Pete

Alex Payne

unread,
Dec 23, 2008, 6:20:06 PM12/23/08
to twitter-deve...@googlegroups.com
If you don't get an error message, what do you get back as an HTTP response?

--
Alex Payne - API Lead, Twitter, Inc.
http://twitter.com/al3x

Peter Denton

unread,
Dec 23, 2008, 6:11:42 PM12/23/08
to twitter-deve...@googlegroups.com
are you handling the rest of the http_code messages?

Cameron Kaiser

unread,
Dec 23, 2008, 6:27:03 PM12/23/08
to twitter-deve...@googlegroups.com

This is where the output from a tracing proxy like Charles may be very
useful.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Any excuse will serve a tyrant. -- Aesop -----------------------------------

Pete Wingard

unread,
Dec 23, 2008, 6:28:11 PM12/23/08
to twitter-deve...@googlegroups.com
don't know. I would have to figure that out. I do know if I send an invalid password there is no tweet but I get a 200 response
--
Pete Wingard

Krumlr.Com
MudSweatAndTears.Com
PixelCast.Net
TigerTailST.Com
& Yougler.Com

you can follow on Twitter
http://www.twitter.com/krumlr

Decatur, GA
404.797.1646
http://yougler.com/pete
netl...@gmail.com

Pete Wingard

unread,
Dec 23, 2008, 6:29:43 PM12/23/08
to twitter-deve...@googlegroups.com
no just whether or not it is 200

Pete Wingard

unread,
Dec 23, 2008, 7:31:01 PM12/23/08
to twitter-deve...@googlegroups.com
it is a 417 error

Alex Payne

unread,
Dec 23, 2008, 7:34:12 PM12/23/08
to twitter-deve...@googlegroups.com
That's almost assuredly the result of a misconfigured proxy.

--

Pete Wingard

unread,
Dec 23, 2008, 7:35:50 PM12/23/08
to twitter-deve...@googlegroups.com
can you tell by looking at the result array?

Pete Wingard

unread,
Dec 23, 2008, 7:38:03 PM12/23/08
to twitter-deve...@googlegroups.com
here is the result array of a test tweet:

Array
(
    [content_type] => text/html; charset=iso-8859-1
    [http_code] => 417
    [header_size] => 192
    [request_size] => 378
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.126771
    [namelookup_time] => 0.002284
    [connect_time] => 0.06419
    [pretransfer_time] => 0.06428
    [size_upload] => 0
    [size_download] => 364
    [speed_download] => 2871
    [speed_upload] => 0
    [download_content_length] => 364
    [upload_content_length] => -1
    [starttransfer_time] => 0.126658
    [redirect_time] => 0
)

Alex Payne

unread,
Dec 23, 2008, 7:40:09 PM12/23/08
to twitter-deve...@googlegroups.com
Probably not? Wouldn't hurt to post it, though.

Pete Wingard

unread,
Dec 23, 2008, 7:41:20 PM12/23/08
to twitter-deve...@googlegroups.com
Array
(
    [content_type] => text/html; charset=iso-8859-1
    [http_code] => 417
    [header_size] => 192
    [request_size] => 378
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.126771
    [namelookup_time] => 0.002284
    [connect_time] => 0.06419
    [pretransfer_time] => 0.06428
    [size_upload] => 0
    [size_download] => 364
    [speed_download] => 2871
    [speed_upload] => 0
    [download_content_length] => 364
    [upload_content_length] => -1
    [starttransfer_time] => 0.126658
    [redirect_time] => 0
)


Pete Wingard

unread,
Dec 23, 2008, 7:43:53 PM12/23/08
to twitter-deve...@googlegroups.com
This is my twitter class I am using to send the update:

class twitter {
private $user;
private $pass;
private $ch;
private $twitterHost = "http://twitter.com/";
public function __construct($username, $passwd) {
$this->user = $username;
$this->pass = $passwd;
/* Create and setup  the curl Session */
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_USERPWD, "$this->user:$this->pass");
curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->ch, CURLOPT_POST, 1);
}
public function __destruct() {
/*clean Up */
curl_close($this->ch);
}

public function setStatus($stat) {
if(strlen($stat) < 1)
return false; 
/*Set the host information for the curl session */
$this->twitterHost .= "statuses/update.xml?status=". urlencode(stripslashes(urldecode($stat)))."&source=krumlrpagekrums";
curl_setopt($this->ch, CURLOPT_URL, $this->twitterHost);
/* Execute and get the http code to see if it was succesfull or not*/
$result = curl_exec($this->ch);
$resultArray = curl_getinfo($this->ch);
if ($resultArray['http_code'] == 200) {
$_SESSION['twitter_result']=$resultArray;// save result to debug
return true;
}
$_SESSION['twitter_result']=$resultArray;
return false;
}
}
?>

Stecki

unread,
Dec 23, 2008, 8:06:40 PM12/23/08
to Twitter Development Talk
(I thought I had succesfully posted a few minutes ago, but can't find
my post)

Same problem here. Getting http status 417 when trying to update a
status - with a script that worked fine for the last weeks (about 5-10
posts a day).

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD,"user:password");
curl_setopt($ch, CURLOPT_URL, $url);
$post=array("status"=>$t);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE,true);
curl_setopt($ch, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_1_1);
$result=trim(curl_exec($ch));
$info=curl_getinfo($ch);
$statuscode=curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);

Peter Denton

unread,
Dec 23, 2008, 7:33:49 PM12/23/08
to twitter-deve...@googlegroups.com
417 - Expectation Failed
The 417 status code means that the server was unable to properly complete the request. One of the headers sent to the server, the "Expect" header, indicated an expectation the server could not meet.

Stecki

unread,
Dec 23, 2008, 8:24:43 PM12/23/08
to Twitter Development Talk
Although I have no idea, why this worked for so long and suddenly
stopped working, adding

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

seemed to do the trick.

(see http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx
)

Pete Wingard

unread,
Dec 23, 2008, 8:31:04 PM12/23/08
to twitter-deve...@googlegroups.com
worked for me too it seems but I will keep testing

Stecki

unread,
Dec 23, 2008, 8:48:29 PM12/23/08
to Twitter Development Talk
> > curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

Would be really interestingt though to know, what the guys at twitter
changed on the api.

Other infos to the general aspect of 417 / http expect:

http://de3.php.net/manual/en/function.curl-setopt.php#82418

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3

Cameron Kaiser

unread,
Dec 23, 2008, 8:51:37 PM12/23/08
to twitter-deve...@googlegroups.com
> > > curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
>
> Would be really interestingt though to know, what the guys at twitter
> changed on the api.

I still haven't seen a Charles trace on what the client is actually sending.
If the client is indeed sending a bogus Expect: header, then all this line is
doing is suppressing it.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com

-- To err is human -- to forgive is not company policy. -----------------------

Alex Payne

unread,
Dec 23, 2008, 8:53:54 PM12/23/08
to twitter-deve...@googlegroups.com
We haven't changed anything with the API. Our operations team is
currently rolling out a new version of Apache, and perhaps this new
version is stricter about client-supplied headers. But I'd
double-check your code first.

--

Stecki

unread,
Dec 23, 2008, 9:02:06 PM12/23/08
to Twitter Development Talk
> > I still haven't seen a Charles trace on what the client is actually sending.
> > If the client is indeed sending a bogus Expect: header, then all this line is
> > doing is suppressing it.

I for my part had never explicitly set an Expect: header. Seems that
Curl is doing this automagically. But until tonight it never was a
problem - so the new apache may indeed be a bit more picky, what to
accept.

My code was:

curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD,"user:pass");
curl_setopt($ch, CURLOPT_URL, $url."?status=".urlencode($t));
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

and I just added

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

to get it to work.

Sorry, I don't know how to get the verbose trace info.


Ed Finkler

unread,
Dec 23, 2008, 9:03:27 PM12/23/08
to twitter-deve...@googlegroups.com
If you're testing your app locally, use Charles to examine the data:

http://www.charlesproxy.com/

--
Ed Finkler
http://funkatron.com
AIM: funka7ron
ICQ: 3922133
Skype: funka7ron

Stecki

unread,
Dec 23, 2008, 9:06:44 PM12/23/08
to Twitter Development Talk
> If you're testing your app locally, use Charles to examine the data:
>
> http://www.charlesproxy.com/

Thanks for the advice; but unfortunately my script runs on a hosted
server. I guess I could pipe the stderr somewhere to get the output or
use a curl callback function. But I am too tired for such things (it
is 3:06 am local time here) :-)

JakeS

unread,
Dec 23, 2008, 11:13:19 PM12/23/08
to Twitter Development Talk
I'm getting the same issue with my client written using the .NET
compact framework. I'm not explicitly setting any Expect headers, but
I'm getting 417 errors when posting.

JakeS

unread,
Dec 23, 2008, 11:23:37 PM12/23/08
to Twitter Development Talk
It looks like .NET requests automatically include "100-continue" in
their Expect header unless you specifically tell it not to. I expect
this server rollout will break almost every client written in .NET,
and possibly a lot of others too.

On Dec 23, 8:06 pm, Stecki <ma...@stecki.de> wrote:
Reply all
Reply to author
Forward
0 new messages