Skip Menu |

This queue is for tickets about the WWW-Facebook-API CPAN distribution.

Report information
The Basics
Id: 28864
Status: resolved
Priority: 0/
Queue: WWW-Facebook-API

People
Owner: unobe [...] cpan.org
Requestors: kalle.bingel [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: photo uploads
Date: Thu, 16 Aug 2007 22:23:39 +0200
To: bug-www-facebook-api [...] rt.cpan.org
From: "Kalle Bingel" <kalle.bingel [...] gmail.com>
Hi, I'm experiencing problems uploading photos, I will always get an "324 Missing or invalid image file." from facebook... After reading and doing some snooping, I found out that the problem might be in the way www-facebook-api is encoding the parameters. It (seems like it) currently sends all parameters using the "simple" format (application/x-www-form-urlencoded), BUT when doing photo uploads, facebook requires the parameters to be sent in MIME multipart format (this according to the following page: http://wiki.developers.facebook.com/index.php/Photos.upload). LWP supports this format with a quite easy implementation, so it should not be a big deal to change... I have gotten it to work by modifying API.pm and replacing the _post_request with the following: sub _post_request { my ( $self, $params, $secret, $sig, $post_params ) = @_; my $data = $params->{'data'}; # save data parameter delete $params->{'data'}; $self->_format_params($params); $sig = $self->generate_sig( params => $params, secret => $secret ); $post_params = [ map { $_ => $params->{$_} } sort keys %{$params} ]; push @{$post_params}, q{sig}, $sig; if( defined $data) { # add data parameter to request, also specifying content-type push( @{$post_params}, 'data', [ undef, 'filename', 'Content-Type' => 'image/jpeg', 'Content' => $data ]); } # Setting Content_type to 'form-data' makes LWP encode it as multipart MIME return $self->ua->post( $self->server_uri, 'Content_type' => 'form-data', 'Content' => $post_params)->content; } This works for me, and I've uploaded several photos to facebook this way... HOWEVER... after looking through and trying to understand the facebook API better as well as this perl module, I suddenly realized that my code alteration should not really work. It does not include the photo data in the signature (I remove it from the $params hash, then it gets encoded and the signature is generated, and then I add it to the parameter list again)... so my code seems as it should generate a signature error, but it doesn't... BUT it sure does when I tried to correct my "bug"... so I don't understand anything... and by the way, my take on the situation is really cludgy anyway, so I hope you can take this input and perhaps do something better with it in a future release? OR, maybe you have already another solution ready which I haven't found yet? Thanx! --Kalle PS Also, I think you should do something about the 64-bit integer problem as I suspect you're aware of (aid and other parameters are 64-bit when returned from facebook, and JSON parses it and perl stores it as a float and looses precision in the process)... the workaround with "use JSON::Any qw(DWIW XS);" I found somewhere currently works for me, but anyway...
Subject: Re: [rt.cpan.org #28864] photo uploads
Date: Wed, 29 Aug 2007 17:37:35 -0700
To: Kalle Bingel via RT <bug-WWW-Facebook-API [...] rt.cpan.org>
From: David Romano <david.romano [...] gmail.com>
Hi Kalle, Kalle Bingel via RT wrote on Thu, Aug 16, 2007 at 01:24:39PM PDT: Show quoted text
> This works for me, and I've uploaded several photos to facebook this > way... HOWEVER... after looking through and trying to understand the > facebook API better as well as this perl module, I suddenly realized > that my code alteration should not really work. It does not include > the photo data in the signature (I remove it from the $params hash, > then it gets encoded and the signature is generated, and then I add it > to the parameter list again)... so my code seems as it should generate > a signature error, but it doesn't... BUT it sure does when I tried to > correct my "bug"... so I don't understand anything... and by the way, > my take on the situation is really cludgy anyway, so I hope you can > take this input and perhaps do something better with it in a future > release?
The signature doesn't include the photo data, because (according to the Facebook docs) the photo data isn't a parameter. The signature just checks that each Facebook parameter has the correct value. So yes, you shouldn't have been including the data as a parameter when calc'ing the signature. Show quoted text
> OR, maybe you have already another solution ready which I haven't found yet?
I have attempted a fix at the problem, and it's in the latest development version (r175) located at: http://code.google.com/p/perl-www-facebook-api/source I'm planning to make a new release tomorrow or Friday. - David -- The first 25 lines -- William Shakespeare, Merchant of Venice, Act V, Scene 1
This bug is resolved in v0.4.5, hitting CPAN shortly.