/Server/SWXPHP/Prior Releases/1.02/php/lib/phpFlickr/README.txt

http://swx-format.googlecode.com/ · Plain Text · 250 lines · 215 code · 35 blank · 0 comment · 0 complexity · 3fbe565a9d7fe85b0b41a9d2fb1c3c28 MD5 · raw file

  1. phpFlickr Class 2.1.0
  2. Written by Dan Coulter (dancoulter@users.sourceforge.net)
  3. Project Homepage: http://www.phpflickr.com/
  4. Sourceforge Project Page: http://www.sourceforge.net/projects/phpflickr/
  5. Released under GNU Lesser General Public License (http://www.gnu.org/copyleft/lgpl.html)
  6. For more information about the class and upcoming tools and applications using it,
  7. visit http://www.phpflickr.com/ or http://www.sourceforge.net/projects/phpflickr/
  8. If you are interested in hiring me for a project (involving phpFlickr
  9. or not), feel free to email me.
  10. Installation instructions:
  11. 1. Copy the files from the installation package into a folder on your
  12. server. They need to be readible by your web server. You can put
  13. them into an include folder defined in your php.ini file, if you
  14. like, though it's not required.
  15. 2. All you have to do now is include the file in your PHP scripts and
  16. create an instance. For example:
  17. $f = new phpFlickr();
  18. The constructor has three arguments:
  19. A. $api_key - This is the API key given to you by flickr.com. This
  20. argument is required and you can get an API Key at:
  21. http://www.flickr.com/services/api/key.gne
  22. B. $secret - The "secret" is optional because is not required to
  23. make unauthenticated calls, but is absolutely required for the
  24. new authentication API (see Authentication section below). You
  25. will get one assigned alongside your api key.
  26. C. $die_on_error - This takes a boolean value and determines
  27. whether the class will die (aka cease operation) if the API
  28. returns an error statement. It defaults to false. Every method
  29. will return false if the API returns an error. You can access
  30. error messages using the getErrorCode() and getErrorMsg()
  31. methods.
  32. 3. All of the API methods have been implemented in my class. You can
  33. see a full list and documentation here:
  34. http://www.flickr.com/services/api/
  35. To call a method, remove the "flickr." part of the name and replace
  36. any periods with underscores. For example, instead of
  37. flickr.photos.search, you would call $f->photos_search() or instead
  38. of flickr.photos.licenses.getInfo, you would call
  39. $f->photos_licenses_getInfo() (yes, it is case sensitive).
  40. All functions have their arguments implemented in the list order on
  41. their documentation page (a link to which is included with each
  42. method in the phpFlickr clasS). The only exceptions to this are
  43. photos_search(), photos_getWithoutGeodata() and
  44. photos_getWithoutGeodata() which have so many optional arguments
  45. that it's easier for everyone if you just have to pass an
  46. associative array of arguments. See the comment in the
  47. photos_search() definition in phpFlickr.php for more information.
  48. Authentication:
  49. As of this release of the phpFlickr class there is only one authentication method
  50. available to the API. This method is somewhat complex, but is far more secure and
  51. allows your users to feel a little safer authenticating to your application. You'll
  52. no longer have to ask for their username and password.
  53. Authentication API - http://www.flickr.com/services/api/auth.spec.html
  54. I know how complicated this API looks at first glance, so I've tried to
  55. make this as transparent to the coding process. I'll go through the steps
  56. you'll need to use this. Both the auth.php and getToken.php file will
  57. need your API Key and Secret entered before you can use them.
  58. To have end users authenticate their accounts:
  59. First, setup a callback script. I've included a callback script that
  60. is pretty flexible. You'll find it in the package entitled "auth.php".
  61. You'll need to go to flickr and point your api key to this file as the
  62. callback script. Once you've done this, on any page that you want to
  63. require the end user end user to authenticate their flickr account to
  64. your app, just call the phpFlickr::auth() function with whatever
  65. permission you need to use.
  66. For example:
  67. $f->auth("write");
  68. The three permissions are "read", "write" and "delete". The function
  69. defaults to "read", if you leave it blank.
  70. Calling this function will send the user's browser to Flickr's page to
  71. authenticate to your app. Once they have logged in, it will bounce
  72. them back to your callback script which will redirect back to the
  73. original page that you called the auth() function from after setting
  74. a session variable to save their authentication token. If that session
  75. variable exists, calling the auth() function will return the permissions
  76. that the user granted your app on the Flickr page instead of redirecting
  77. to an external page.
  78. To authenticate the app to your account to show your private pictures (for example)
  79. This method will allow you to have the app authenticate to one specific
  80. account, no matter who views your website. This is useful to display
  81. private photos or photosets (among other things).
  82. *Note*: The method below is a little hard to understand, so I've setup a tool
  83. to help you through this: http://www.phpflickr.com/tools/auth/.
  84. First, you'll have to setup a callback script with Flickr. Once you've
  85. done that, edit line 12 of the included getToken.php file to reflect
  86. which permissions you'll need for the app. Then browse to the page.
  87. Once you've authorized the app with Flickr, it'll send you back to that
  88. page which will give you a token which will look something like this:
  89. 1234-567890abcdef1234
  90. Go to the file where you are creating an instance of phpFlickr (I suggest
  91. an include file) and after you've created it set the token to use:
  92. $f->setToken("<token string>");
  93. This token never expires, so you don't have to worry about having to
  94. login periodically.
  95. Using Caching:
  96. Caching can be very important to a project. Just a few calls to the Flickr API
  97. can take long enough to bore your average web user (depending on the calls you
  98. are making). I've built in caching that will access either a database or files
  99. in your filesystem. To enable caching, use the phpFlickr::enableCache() function.
  100. This function requires at least two arguments. The first will be the type of
  101. cache you're using (either "db" or "fs")
  102. 1. If you're using database caching, you'll need to supply a PEAR::DB connection
  103. string. For example:
  104. $flickr->enableCache("db", "mysql://user:password@server/database");
  105. The third (optional) argument is expiration of the cache in seconds (defaults
  106. to 600). The fourth (optional) argument is the table where you want to store
  107. the cache. This defaults to flickr_cache and will attempt to create the table
  108. if it does not already exist.
  109. 2. If you're using filesystem caching, you'll need to supply a folder where the
  110. web server has write access. For example:
  111. $flickr->enableCache("fs", "/var/www/phpFlickrCache");
  112. The third (optional) argument is, the same as in the Database caching, an
  113. expiration in seconds for the cache.
  114. Note: filesystem caching will probably be slower than database caching. I
  115. haven't done any tests of this, but if you get large amounts of calls, the
  116. process of cleaning out old calls may get hard on your server.
  117. You may not want to allow the world to view the files that are created during
  118. caching. If you want to hide this information, either make sure that your
  119. permissions are set correctly, or disable the webserver from displaying
  120. *.cache files. In Apache, you can specify this in the configuration files
  121. or in a .htaccess file with the following directives:
  122. <FilesMatch "\.cache$">
  123. Deny from all
  124. </FilesMatch>
  125. Alternatively, you can specify a directory that is outside of the web server's
  126. document root.
  127. Uploading
  128. Uploading is pretty simple. Aside from being authenticated (see Authentication
  129. section) the very minimum that you'll have to pass is a path to an image file on
  130. your php server. You can do either synchronous or asynchronous uploading as follows:
  131. synchronous: sync_upload("photo.jpg");
  132. asynchronous: async_upload("photo.jpg");
  133. The basic difference is that synchronous uploading waits around until Flickr
  134. processes the photo and returns a PhotoID. Asynchronous just uploads the
  135. picture and gets a "ticketid" that you can use to check on the status of your
  136. upload. Asynchronous is much faster, though the photoid won't be instantly
  137. available for you. You can read more about asynchronous uploading here:
  138. http://www.flickr.com/services/api/upload.async.html
  139. Both of the functions take the same arguments which are:
  140. Photo: The path of the file to upload.
  141. Title: The title of the photo.
  142. Description: A description of the photo. May contain some limited HTML.
  143. Tags: A space-separated list of tags to apply to the photo.
  144. is_public: Set to 0 for no, 1 for yes.
  145. is_friend: Set to 0 for no, 1 for yes.
  146. is_family: Set to 0 for no, 1 for yes.
  147. Replacing Photos
  148. Flickr has released API support for uploading a replacement photo. To use this
  149. new method, just use the "replace" function in phpFlickr. You'll be required
  150. to pass the file name and Flickr's photo ID. You need to authenticate your script
  151. with "write" permissions before you can replace a photo. The arguments are:
  152. Photo: The path of the file to upload.
  153. Photo ID: The numeric Flickr ID of the photo you want to replace.
  154. Async (optional): Set to 0 for a synchronous call, 1 for asynchronous.
  155. If you use the asynchronous call, it will return a ticketid instead
  156. of photoid.
  157. Other Notes:
  158. 1. Many of the methods have optional arguments. For these, I have implemented
  159. them in the same order that the Flickr API documentation lists them. PHP
  160. allows for optional arguments in function calls, but if you want to use the
  161. third optional argument, you have to fill in the others to the left first.
  162. You can use the "NULL" value (without quotes) in the place of an actual
  163. argument. For example:
  164. $f->groups_pools_getPhotos($group_id, NULL, NULL, 10);
  165. This will get the first ten photos from a specific group's pool. If you look
  166. at the documentation, you will see that there is another argument, "page". I've
  167. left it off because it appears after "per_page".
  168. 2. Some people will need to ues phpFlickr from behind a proxy server. I've
  169. implemented a method that will allow you to use an HTTP proxy for all of your
  170. traffic. Let's say that you have a proxy server on your local server running
  171. at port 8181. This is the code you would use:
  172. $f = new phpFlickr("[api key]");
  173. $f->setProxy("localhost", "8181");
  174. After that, all of your calls will be automatically made through your proxy server.
  175. 3. NOTE: phpFlickr's support of 23's API is only supported in 1.x
  176. versions of phpFlickr. This will not work in 2.x until they
  177. begin using serialized PHP. Don't even try!
  178. As of phpFlickr version 1.5, I've decided to add support for 23's API. The
  179. reasoning behind this is that 23 (a European-based photo sharing community)
  180. has released an API based on Flickr's. Their main reason for doing so seems
  181. to be compatibility for developers. This means that your app may instantly
  182. start working for their users as well. All you'll need to do to get phpFlickr
  183. to work with 23 is to use the following code:
  184. $f = new phpFlickr("[api key]"); //With 23's API, you can make up your own API
  185. //key or use one assigned to you from Flickr
  186. $f->setService("23");
  187. To change back to flickr (the default setting):
  188. $f->setService("flickr");
  189. I'm including this support with a few caveats:
  190. -Currently, I'm only willing to support 23 insofar as they duplicate the
  191. functionality of Flickr. If they begin to stray, create new methods, or
  192. implement their own authentication scheme, I may end support of their
  193. API at my discretion.
  194. -There are some differences between the services. Their "square" thumbnail
  195. format is larger than Flickr's. Also the photo page URLs have a different
  196. format than Flickr's. I haven't used 23 much myself, so there may be
  197. other important differences that I don't know about.
  198. -Not all of Flickr's API methods have been implemented by 23. As far as I
  199. can tell, they have setup dummy methods that will return empty result sets.
  200. -According to their documentation, 23 does not yet support the "web application"
  201. style authentication that Flickr does. This means that your app will not
  202. authenticate to 23 as it would to Flickr.
  203. More information about 23 and their API:
  204. Homepage: http://www.23hq.com/
  205. About 23: http://www.23hq.com/23/about
  206. Switching from Flickr's API: http://www.23hq.com/doc/api/switch
  207. API Documentation: http://www.23hq.com/doc/api/index
  208. Terms of Service: http://www.23hq.com/23/terms
  209. That's it! Enjoy the class. Check out the project page (listed above) for updates
  210. and news. I plan to implement file uploads and functions to aggregate data from
  211. several different methods for easier use in a web application. Thanks for your
  212. interest in this project!
  213. Please email me or submit all problems or questions to the Help topic on
  214. the phpFlickr forums:
  215. http://www.phpflickr.com/forums/