phpoauthtokenflickrphpflickr

Flickr API - phpFlickr - Display private pictures with photosets_getPhotos()


I want to display Flickr private pictures on a page.

I have 3 files in my directory :

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.


Solution

  • Hey almost 2 years ago myself... Anyway.

    I found a solution a bit later after the question and never posted a reply. I think it could be interesting, even if late, for other people :

    So, pretty sure there is something smarter to do but I didn't find it. I found "a way" to do what I needed.

    I needed to make a private web page with galeries of private photos.

    <?php
    require_once("phpFlickr.php");
    $f = new phpFlickr('myapikey','myapisecret');
    $f->enableCache("fs", "cache");
    
    //This is what I really missed: the token number.
    $f->setToken('myratherlongtoken-number');
    //Dan Coulter explains it in the documentation of phpFlickr
    //He also provides a tool to ask a token.
    
    $username="My Username";
    $result = $f->people_findByUsername($username);
    $nsid = $result["id"];
    ?>
    
    //After, you can display infos of your private album (knowing its ID)
    //Such as primary photoset image, total number of photos...
    <?php $infos = $f->photosets_getInfo('12345MyAlbumId67890'); ?>
    
    //Or even process a loop to display a gallery
    <?php $photos = $f->photosets_getPhotos('12345MyAlbumId67890','','5');
    foreach ($photos['photoset']['photo'] as $photo): ?>