1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| <?php
require_once("phpFlickr/phpFlickr.php");
// Create new phpFlickr object
$f = new phpFlickr("[API Key]");
$f->enableCache(
"db",
"mysql://[username]:[password]@[server]/[database]"
);
$i = 0;
if (!empty($_POST['username'])) {
// Find the NSID of the username inputted via the form
$person = $f->people_findByUsername($_POST['username']);
// Get the friendly URL of the user's photos
$photos_url = $f->urls_getUserPhotos($person['id']);
// Get the user's first 36 public photos
$photos = $f->people_getPublicPhotos($person['id'], NULL, NULL, 36);
// Loop through the photos and output the html
foreach ((array)$photos['photos']['photo'] as $photo) {
echo "<a href=$photos_url$photo[id]>";
echo "<img border='0' alt='$photo[title]' ".
"src=" . $f->buildPhotoURL($photo, "Square") . ">";
echo "</a>";
$i++;
// If it reaches the sixth photo, insert a line break
if ($i % 6 == 0) {
echo "<br>\n";
}
}
}
?>
<h3>Enter a username to search for</h3>
<form method='post'>
<input name='username'><br>
<input type='submit' value='Display Photos'>
</form>
<p><a href="source">View Source</a></p> |
Typo on line 25? should read "$f->buildPhotoURL($photo, "Square")"
hello!
thank you for your work.
how can i disable the cache?
i'm tryng to use this code…but something is wrong. When i search for the username….doesn't apper anythings… maybe because i don't passed the $f->enableCache(
"db",
"mysql://[username]:[password]@[server]/[database]"
??
take a look there http://www.super-web.it/provaapi/flickrapi.php
thank you.
If you just leave the cache method call out, it won't ever activate the cache.
Hi .
Something that i don't understand, is why i have to fill with an API key, i mean, only for displaying pictures.
On this online exemple, did you fill in with your API KEY ?
You can directly code the HTML to display images from Flickr without an API key. The API lets you do a more automated fetching of images to display, like fetching the last 10 images in your photostream. To do the more advanced things that the API lets you do, you need an API key. And yes, I did fill in an API key in the example.
Ok. Thank you for your answear !