Siouw
Siouw

Reputation: 53

Php Flickr authentication to access private photos

I would like to use Flickr as a repository for my website photos. The idea is to upload them to Flickr with "private" permissions so that no one can see them there but to display them in a public gallery on my website.

I gathered I need authentication (with Oath presumably). But I don't want my website visitors to have to login or go through some kind of authentication process. I want it to be silent / in the background.

Is that feasible at all?

I'm using the (standard) php flickr class with the Oauth add-on from: http://asociaux.fr/post/2012/01/06/Authentification-API-Flickr-Oauth-PHPFlickr

And of course I've already created my api key/secret.

Though I'm familiar with the standard use of php flickr (without authentication), I've absolutely no idea where to start with this auth thingy.

I've started with the first method (as described in the above site) :

$f = new phpFlickr($cle_api, $cle_secret_api);  
$f->getRequestToken($callback); 

but the thing is, flickr is granting "me" (the browser user) access and not the server. Which is obviously not what I want?

Can someone pointing me to the right direction?

NB : right now I'm interested in the reading part of the process (the writing part will come later).

Upvotes: 1

Views: 2212

Answers (1)

mihkelo
mihkelo

Reputation: 111

It is possible with phpFlickr class. What I did to get it work with my private photos:

  1. Set up phpFlickr on public domain (example.com)
  2. Generate Flickr API key and point authentication callback to auth.php (example.com/phpflickr/auth.php)
  3. Now, set parameters on getToken.php and run it on browser. I didn't got this work (it didn't display my token), but it will redirect you to page with frob parameter.
  4. Go to http://www.flickr.com/services/api/explore/?method=flickr.auth.getToken
  5. Paste the frob value you just copied (the "MORENUMBERS") into the value box.
  6. Check sign call with full permissions.
  7. Underneath, your token should pop up.
  8. Copy the token number and use this as hard-coded parameter in your script:

    $conf = array(
      'token' => '[token]',
      'key' => '[key]',
      'secret' => '[secret]'
    );
    require_once("vendor/phpflickr/phpFlickr.php");
    $f = new phpFlickr($conf['key'], $conf['secret']);
    $f->setToken($conf['token']);
    
    //change this to the permissions you will need
    $f->auth("read");
    
    // you can now call all API methods
    

Hopfully this helps.

Upvotes: 1

Related Questions