1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Next Door
    Rep Power

    How to use an api with PHP. Flickr for example.


    I want to to find out, is it me or this API is not clear.

    Flickr. In a nutshell what I had in mind was that:

    1 - Flickr provides a request format. Either XML, or array of data to be POSTed to them using curl_init or send to them via GET.

    2 - Then flickr provides a response xml of data.

    Basically the same way Yahoo weather works. Something like:
    PHP Code:
    $url 'http://weather.yahooapis.com/forecastrss?w=7226269&u=c';
    $xml file_get_contents($url);
    $xml simplexml_load_string($xml);
    $node $xml->channel->item;
    $children $node->children('http://xml.weather.yahoo.com/ns/rss/1.0');
    $condition $children->condition;
    $attributes $condition->attributes();
    "<br />Weather Condition: ";
    "<strong>".$attributes['text'] . "</strong>, " $attributes['temp'] ." &deg;C<br /><br />"

    But I find the documentation confusing and not straight forward.

    1 - There is sample of php code which results in
    Deprecated: Assigning the return value of new by reference is deprecated in /Applications/XAMPP/xamppfiles/htdocs/flickr/XML/Tree.php on line 262
    Parse error: syntax error, unexpected T_CLONE, expecting T_STRING in /Applications/XAMPP/xamppfiles/htdocs/flickr/XML/Tree.php on line 297
    2 - They provide sample for response formats on the main API Documentaiton on the right column but there are no working sample of sending request to an end point which is also very important. There are some user contribution scripts which they say you can use at your own risk!

    If you were to use this, how would you find your way? I really want to learn this because it may be me who is new to this ( I doubt it).

    Thank you
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    both PHP libraries linked at Flickr (phpFlickr and that iamcal stuff) are hopelessly outdated, don't use them. They are written for PHP 4. Looks like Flickr doesn't really care about the code examples.

    I'd Google for current PHP scripts and libraries for Flickr like this one. It also hasn't been updated since 3 years, but at least it's specifically written for PHP 5. Of course you can also use the old code for "inspiration", but don't expect it to actually run without errors.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo