Hey Kevin,
Although I cannot help you with the finer details of PHP and curl (I
am using C# and wrote my own library for the Twitter API), I can still
tell you that the image methods were the only ones I had difficulty
with.
Is there any way you can capture the outgoing post data using
WireShark or equivalent tool and post it here? The image update
methods were both very finicky about how you passed the post data.
Here is the header and post data from a successful call to
update_profile_image.
The header (note the Content-Type and boundary):
{Content-Type: multipart/form-data; boundary=894008af-9071-43eb-
a9f2-9fdbb8da4e05
X-Twitter-Client: DeBettaTweet
X-Twitter-Version: 0.2
X-Twitter-URL: http://sqlblog.com
}
The post data (prior to encoding to character set "iso-8859-1"):
--894008af-9071-43eb-a9f2-9fdbb8da4e05
source=DeBettaTweet
--894008af-9071-43eb-a9f2-9fdbb8da4e05
Content-Disposition: form-data); name="image");
filename="twitterProfilePhoto.jpg"
Content-Type: image/jpeg
ÿØÿà\0JFIF\0 ...ACTUAL IMAGE DATA IS ABRIDGED TO KEEP THIS REPLY
SHORT... ʧ¯ÿÙ
--894008af-9071-43eb-a9f2-9fdbb8da4e05--
On Jan 20, 4:24 pm, Matt Sanford <[email protected]> wrote:
> Hi Kevin,
>
> MY PHP is pretty rusty so I started working on a script for this
> to reproduce your issue. I'm seeing odd behavior once I add ;type= to
> the file name, and when I went looking I found a bu report about it
> [1]. The followup [2] says this was fixed in the CVS version of PHP on
> 2008-11-27, which is pretty bleeding edge. Since curl is working
> correctly and this is a problem with the PHP/curl bindings I'm not
> sure I can provide much guidance.
>
> Thanks;
> — Matt Sanford
>
> [1] -http://aspn.activestate.com/ASPN/Mail/Message/php-dev/3680378
> [2] -http://aspn.activestate.com/ASPN/Mail/Message/php-dev/3680431
>
> On Jan 20, 2009, at 11:55 AM, Kevin Thompson wrote:
>
>
>
>
>
> > Peter,
> > I tried manually passing the image/jpg, but that didnt seem to
> > help. Still returning a 403.
>
> > The following command works fine, so there must be something wrong
> > with the way I'm passing the mime type to curl in PHP:
>
> > curl -F '[email protected];type=image/png' -H
> > 'Expect:' -u
> > {username}:{password}http://twitter.com/account/update_profile_image.xml
>
> > On Jan 20, 7:57 am, DeBetta <[email protected]> wrote:
> >> I had similar issues when first working with images. I ended up using
> >> "image/jpg" for the mimetype regardless of the actual type of file
> >> and
> >> that seemed to clear up the issue.
>
> >> --Peter
>
> >> On Jan 20, 8:46 am, Kevin Thompson <[email protected]> wrote:
>
> >>> Matt,
> >>> I tried changing my script to generate a gif, and my issues with
> >>> twitter dissapeared, but my image was no longer rendering properly
> >>> so
> >>> I switched the output back to png and added the mimetype to the
> >>> image
> >>> data, but now I'm not getting any response.
>
> >>> foreach($_POST as $key => $var){
> >>> $POST[$key] = htmlspecialchars($var,ENT_QUOTES);
> >>> }
>
> >>> if($POST['twittername'] != '' && $POST['twitterpass'] !=
> >>> ''){
>
> >>> $url = 'http://twitter.com/users/show/'.
> >>> urlencode($POST
> >>> ['twittername']) . '.xml';
> >>> $curl = curl_init($url);
>
> >>> curl_setopt($curl, CURLOPT_VERBOSE, 1);
> >>> curl_setopt($curl, CURLOPT_NOBODY, 0);
> >>> curl_setopt($curl, CURLOPT_HEADER, 0);
> >>> curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
> >>> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
> >>> $response = curl_exec($curl);
> >>> curl_close($curl);
>
> >>> $user = new SimpleXMLElement($response);
> >>> $image_array = explode('.',$user-
> >>> >profile_image_url);
>
> >>> $filename = $POST['twittername'] . '-' . time() .
> >>> '.png';
> >>> $badge = imagecreatefrompng($POST['badge']);
> >>> switch($image_array[(sizeof($image_array) - 1)]){
> >>> case 'jpg':
> >>> $avatar =
> >>> imagecreatefromjpeg($user->profile_image_url);
> >>> break;
> >>> case 'png':
> >>> $avatar = imagecreatefrompng($user-
> >>> >profile_image_url);
> >>> break;
> >>> case 'gif':
> >>> $avatar = imagecreatefromgif($user-
> >>> >profile_image_url);
> >>> break;
> >>> default:
> >>> $avatar = imagecreatefrompng($user-
> >>> >profile_image_url);
> >>> break;
> >>> }
>
> >>> imagealphablending($badge,1);
> >>> imagealphablending($avatar,1);
> >>> imagecopy($avatar,$badge,0,0,0,0,48,48);
> >>> imagepng($avatar,$filename);
>
> >>> //*
> >>> $url =
> >>> 'http://twitter.com/account/update_profile_image.xml'
> >>> ;
>
> >>> $curl = curl_init();
> >>> curl_setopt($curl, CURLOPT_URL, "$url");
> >>> curl_setopt($curl, CURLOPT_POST, 1);
> >>> curl_setopt($curl, CURLOPT_HTTPHEADER,
> >>> array('Expect:'));
> >>> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
> >>> curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 4);
> >>> curl_setopt($curl,
> >>> CURLOPT_POSTFIELDS,array('image' => "@
> >>> $filename;type=image/png"));
> >>> curl_setopt($curl, CURLOPT_USERPWD,
> >>> $POST['twittername'] . ':' .
> >>> $POST['twitterpass']);
> >>> $response = curl_exec($curl);
> >>> $info = curl_getinfo($curl);
> >>> curl_close($curl);
>
> >>> imagedestroy($badge);
> >>> imagedestroy($avatar);
> >>> unlink($filename);
> >>> // */
>
> >>> On Jan 19, 12:18 pm, Matt Sanford <[email protected]> wrote:
>
> >>>> Hi Kevin,
>
> >>>> I find that error message misleading. If the image could not
> >>>> be
> >>>> processed for any reason the error says "possibly too big". That's
> >>>> normally the case with user uploads but it seems like from the API
> >>>> it's more often something else. Looking back through the Google
> >>>> Group
> >>>> it seems like GIF is predominantly the issue. If you create a
> >>>> similar
> >>>> 1x1 PNG does it do the same thing? We support GIF and it should
> >>>> work,
> >>>> but knowing what works and what doesn't will help narrow it down.
>
> >>>> Thanks;
> >>>> — Matt Sanford / @mzsanford
>
> >>>> On Jan 19, 2009, at 10:01 AM, DeBetta wrote:
>
> >>>>> I just tested the update_profile_image API call and sent a 190K
> >>>>> image
> >>>>> without issue.
>
> >>>>> What kind of image are you trying to post? Do you have sample
> >>>>> code you
> >>>>> can share?
>
> >>>>> --Peter
>
> >>>>> On Jan 19, 11:16 am, Kevin Thompson <[email protected]>
> >>>>> wrote:
> >>>>>> I'm attempting to write a simple script to update the user's
> >>>>>> profile
> >>>>>> image, but I am getting a response that the image is possible
> >>>>>> too big
> >>>>>> each time. The file that I'm attempting to set as the user
> >>>>>> avatar is
> >>>>>> no larger than 5k, and it fails.
>
> >>>>>> I created a 1px by 1px white gif which weighed in at about 43
> >>>>>> bytes
> >>>>>> and it worked.
>
> >>>>>> My suspicion is that for some reason the API is not correctly
> >>>>>> calculating the file size of the image data, or it's checking
> >>>>>> for a
> >>>>>> much smaller value than 700k.- Hide quoted text -
>
> >>> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -