Details make the difference

While playing around with the Zemanta API today, I bumped into a small problem. I first attempted to do it in symfony using the sfWebBrowserPlugin, but as I kept running into a 403 Developer Inactive error, I decided to try other tools, to see if the problem was on my side or on Zemanta's side. The problem, as it turned out, was on my side.

The Zemanta API is quite a simple API at this point, but it works nicely. To give some background, you feed the API with a text, Zemanta analyses this text, and offers links, images and tags as a suggestion for usage with the text. Excellent for weblogs and magazines looking to enrich their content. The API call therefore is nothing more than a POST request that requires a few parameters: text, return format, method (currently simply zemanta.suggest) and an API key. Should not be too hard, you'd think?

Think again
Since it's a simple request, I immediately decided to use the already installed sfWebBrowserPlugin for this request. It has a very simple API, and should work fine. However, I couldn't get it to work correctly. I kept getting a 403 Developer Inactive error. A weird error, which led me to believe I might be using an incorrect API key. I double checked it with the key in my control panel, but nope, everything was correct.

I need a second opinion
I wasn't making any progress, so on to the next attempt: Use another tool to do the same thing. I decided to dust off my Zend_Http_Client knowledge and use that instead. After 10 minutes of work (well, mostly reading into the exact syntax of doing the call) I had a working example. Including a valid response. So no problem on the Zemanta side, the developer was active! It was something in symfony or the plugin.

Let's squash that bug
I couldn't have it that something worked fine in Zend Framework, but wouldn't work in my beloved symfony. So I started trying other things, trying to chase the parameters sent with the request, but all seemed fine. After looks of searching through the code, trying the different adapters that come with sfWebBrowserPlugin, and comparing the approach of sfWebBrowserPlugin with the approach of Zend_Http_Client, I noticed one thing: the call to http_build_query() was different.

sfCurlAdapter was calling http_build_query($parameters) where Zend_Http_Client was calling http_build_query($this->paramsPost, '', '&' ). Notice the two extra parameters, of which the second is the most important in this situation. It turns out if you leave the seperator parameter empty, it defaults to the encoded &, which clearly the Zemanta API at least could not handle (and perhaps others as well). When I changed the call to http_build_query($parameters, null, '&' ), the problem was solved! I got back the expected XML response using the sfWebBrowserPlugin.

Contribute!
As I'd suggest every Open Source user to do, I immediately opened a bug for this so that it can be fixed by the developer of the plugin. Contributing back fixes like these to the project helps all users, and eventually makes the project so much better

Update!
It seems I have been stupid all along. The bug was already fixed in the sfWebBrowserPlugin a long time ago. I installed the plugin a long time ago into my project and never since updated it to the latest version, not even when encountering this bug. My bad, sorry Francois! :)


Add comment

Comments

gravatar Shahar Evron: I'm glad Zend_Http_Client could help ;)
July 9, 2008
gravatar Open: Zend_Http_Client works great!
July 18, 2008

Php5_zce_logo

Upcoming events

I will be speaking 17-02-2012: Techademy Trainingday February
I will be speaking 23-02-2012: Zend Webinar: Git for Subversion Users

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam apache api apple article articles atk atkMetaNode audioscrobbler automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp clear cms cologne common sense communities community components conference conferences contest continuous integration contribute contribution crisis css custom d-day datetime DbFinderPlugin decorator decorators deployment devdays development directoryindex docblox doctrine documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook finland flickr fork framework frameworks freelance freeze frontend fun game games geoip germany getting real git github gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz photo php php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2012 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1