March 31st, 2013, 06:25 PM
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:
$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();
echo "<br />Weather Condition: ";
echo "<strong>".$attributes['text'] . "</strong>, " . $attributes['temp'] ." °C<br /><br />";
But I find the documentation confusing and not straight forward.
1 - There is sample of php code which results in
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).
March 31st, 2013, 06:55 PM
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.