Revised Phlickr getToken Script

Recently have been trying out the API available at http://www.flickr.com/services/api. To do this, I have been searching and testing all the available Flickr API wrappers available out there in AS3 and PHP.

The AS3 version is well documented and works as well as an API in flash can. What I needed was a good PHP library, and I found one called Phlickr.

It is maintained by Andrew Morton, as well as a host of contributors. It is written for PHP 5, and works like the dream I was hoping for, so kudos to Andrew!

My only criticism is in the documentation, samples, and tools that are located on the Phlickr site.
I understand that what goes into writing something like this so I am not putting it down for this, I’m not putting it down at all! What I am doing is posting a revised Authentication Token script of my own to use in place of Andrew’s provided one.

His script is simple and straight forward and meant to be ran from command-line, which is what he was going for. I wanted a little more info, because it took me quite some time to find out what running this script actually needed. There is also something wrong, the ‘frob’ sent to the Flickr auth url is not the same ‘frob’ needed to set the auth token, at least not in my experiences.

So… I simply revised what he had, made it more self-contained, and explained extensively step by step from within the command-line.

What you need to run this script is…

Revised Phlickr getToken Script

Thanks again Andrew!


Posted

in

, ,

by

Comments

9 responses to “Revised Phlickr getToken Script”

  1. Joe Privett Avatar
    Joe Privett

    Hi, I tried the phlickr library and you'r right, there is very little EASY documentatoin that allows you to implement quickly. I am having trouble with it …. i get the 'Invalid auth token' error – see http://rs.thisversion.com/phlickr.php . I noticed that you mentioned somethign about there being a problem with the frob and i think this is the problem i am having – can you help ? I don't want to use phlickr with the commend line, but instead using web-based php scripts!

    1. jimisaacs Avatar

      Joe,

      I will assume that you are beyond a beginner in PHP since you are trying out this library.
      I will also say that this post was made some time ago, and the Phlickr library may have been updated since then.

      I undrstand that command-line php is kind of pointless for web development. At the same time it is useful in writing something for quick testing.

      If you are not familiar with php from command line, I would some research as it is quite useful. No need to worry about forms to test things, it's just a fast way to pass input to and output from PHP.
      <a href=”http://us2.php.net/features.commandline” target=”_blank”>http://us2.php.net/features.commandline

      Notice the STDIN constant in that script. It is "Standard Input", which just means within the shell, pause the buffer and wait for a user's input.

      To run that script "getToken.php" within terminal or whatever command-line tool your operating system has.
      You can run this script simple by typing this command :

      php /path/toscript/getToken.php

      Then the script will run and you can follow the instructions.
      The logic of the script is pretty straight forward from top down. So I believe if you simple want to convert this into a web based script it could be fairly easy.

      Just for clarification, you don't have to run Phlickr from command-line, only this script I have posted.
      It is supposed to be just a fast way to test things, that's all. Phlickr works regardless of being called from command line or a browser.

      Yes there was a problem with the frob. Andrew assumed in his script that the'frob'sent to the Authentication URL would be the same 'frob' needed to send a request for a token. This is wrong, they are different, and the script I have posted here addresses that.

      Also if you are just trying to test if the library works, there are a lot of flickr API requests that don't need any kind of authentication, you can try those first.

      Let me know if any of this helped. If not be more specific with what you need, and I'll give my best 😉

  2. Joe Privett Avatar
    Joe Privett

    Thanks Jim. I got your script working and it produced the necessary config file for use with Phlickr – thanks. In doing so, it highlighted that I had the format of my config file incorrect, i.e. i put each of the parameters on a seperate line with a new-line at the end, whne in fact, they should all be on the same line – DOH!!

    I am progressing slowly with Phlickr (slowly) … and have ordered the book that Andrew Morton co-wrote in an attempt to shed some more light on it. Cheers.

    1. jimisaacs Avatar

      I'm just getting into all these popular available frameworks out there, one of them and the most popular being the Zend Framework. A lot of these things have API wrappers built in to them. May be an option if you haven't thought about it.

  3. Steve Squires Avatar
    Steve Squires

    The download link doesn't work here. Is this file still available? I keep getting an invalid frob error whenever I try to set the authtoken.

    1. jimisaacs Avatar

      Thanks for the heads up, I'll fix it shortly. Seems like a plugin issue.

    2. jimisaacs Avatar

      Should be fixed now, thanks again!

  4. Blair Rush Avatar
    Blair Rush

    Sorry for bringing up something so old however I am curious as to what the frob that you send really is. I was able to get your script working but I want to be able to create my own token and I can not get this to work. My question is basically what do you differently to the when getting the frob that makes it work with setAuthTokenFromFrob()?

    1. Jim Isaacs Avatar

      Blair, unfortunately I can’t guarantee anything about this script anymore as it is going on 8 years old. Back when I wrote this, I think the issue was that the frob used to with buildAuthUrl() is not the same as what is expected for setAuthTokenFromFrob(). You need one to send the initial auth request, but then after the user authenticates, you get a new one at your callback url (generated by flickr api), and that is the one you give to setAuthTokenFromFrob().

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.