I want to display Flickr private pictures on a page.
- I have an API + Secret.
- I use phpFlickr class by Dan Coulter : http://phpflickr.com
- I started something with David Walsh post : http://davidwalsh.name/flickr-php
- I set the callback URL of my API key to : http://mydomain.com/mydirectory/flickr.php
I have 3 files in my directory :
- phpFlickr.php (the class)
- start.php (the auth script)
- flickr.php (to display pictures)
Here is the content of start.php :
<?php
session_start();
require_once('phpFlickr.php');
$flickr = new phpFlickr('myapikey','myapisecret', true);
if(empty($_GET['frob'])) {
$flickr->auth('read');
}
else {
$flickr->auth_getToken($_GET['frob']);
header('Location: flickr.php');
exit();
}
?>
Here is the content of flickr.php :
<?
require_once('phpFlickr.php');
$flickr = new phpFlickr('myapikey','myapisecret', true);
$f->enableCache("fs", "cache");
$photos = $f->photosets_getPhotos('myPhotoAlbumIdWithPrivatePicturesInIt', 5);
foreach ($photos['photoset']['photo'] as $photo): ?>
<img src="<?= $f->buildPhotoURL($photo, 'square') ?>" /><br />
<? endforeach; ?>
This is the error message I get :
"The Flickr API returned the following error: #1 - Photoset not found"
But when I use : http://www.flickr.com/services/api/explore/flickr.photosets.getPhotos I get results. The photoset exists.
Dan Coulter writes :
"*To authenticate the app to your account to show your private pictures:
This method will allow you to have the app authenticate to one specific account, no matter who views your website. This is useful to display private photos or photosets (among other things).
Note: The method below is a little hard to understand, so I've setup a tool to help you through this:
http://www.phpflickr.com/tools/auth/.
First, you'll have to setup a callback script with Flickr. Once you've done that, edit line 12 of the included getToken.php file to reflect which permissions you'll need for the app. Then browse to the page. Once you've authorized the app with Flickr, it'll send you back to that page which will give you a token which will look something like this:
1234-567890abcdef1234
Go to the file where you are creating an instance of phpFlickr (I suggest an include file) and after you've created it set the token to use:
$f->setToken("[token string]");
This token never expires, so you don't have to worry about having to login periodically.*"
Therefore, I think I have an authentication problem. Which would explain that the photoset "doesn't exist".
But where am I wrong ?
Is there a way to make it simpler in 1 script instead of 2 ?
Thank you in advance for your help.