Beispiel #1
0
 public static function getCommentList(Phlickr_Api $api, $photo_id)
 {
     $request = $api->createRequest(self::XML_METHOD_NAME, array("photo_id" => $photo_id));
     if (is_null($request)) {
         throw new Phlickr_Exception('Could not create a Request flickr.photos.comments.getList.');
     } else {
         return new Phlickr_CommentList($request);
     }
 }
 /**
  * Constructor
  *
  * The PhotosetList requires a User Id. If $userId is null the class will
  * try to use the $api->getUserId().
  *
  * @param   object Phlickr_API $api
  * @param   string $userId User Id. If this isn't provided, the API's User
  *          Id will be used instead.
  * @throws  Phlickr_Exception
  */
 function __construct(Phlickr_Api $api, $userId = null)
 {
     if (isset($userId)) {
         $this->_userId = $userId;
     } else {
         $this->_userId = $api->getUserId();
     }
     if (is_null($this->_userId)) {
         throw new Phlickr_Exception('The photoset needs a User Id.');
     }
     parent::__construct($api->createRequest(self::getRequestMethodName(), self::getRequestMethodParams($this->_userId)), self::XML_RESPONSE_ELEMENT, self::XML_RESPONSE_LIST_ELEMENT);
 }
Beispiel #3
0
 function testExecuteMethod_ThrowsExceptionWhenThrowOnErrorSpecified()
 {
     $api = new Phlickr_Api('INVALID_KEY_FOR_TESTING', 'INVALID_SECRET');
     try {
         $api->executeMethod('flickr.test.echo', array());
     } catch (Phlickr_Exception $ex) {
         $this->assertEquals('Invalid API Key (Key not found)', $ex->getMessage());
         $this->assertEquals(100, $ex->getCode());
         return;
     } catch (Exception $ex) {
         $this->fail('threw the wrong type (' . get_class($ex) . ') of exception.');
     }
     $this->Fail('An exception should have been thrown.');
 }
Beispiel #4
0
function display_mini($photoid)
{
    $api = Phlickr_Api::createFrom(API_CONFIG_FILE);
    $p = new Phlickr_Photo($api, $photoid);
    $title = $p->getTitle();
    print '<small>' . $title . '</small><a href="' . $p->buildUrl() . '"><img src="' . $p->buildImgURL('t') . '" border="0" /></a>';
}
Beispiel #5
0
 private function checkTicket($ticketsId, $type)
 {
     $return = ["status" => self::UPLOAD_STATE_FAILED, "dist_id" => null];
     $response = $this->_api->executeMethod("flickr.photos.upload.checkTickets", ["tickets" => $ticketsId]);
     if (!$response->isOk()) {
         throw new Bridge_Exception_ApiConnectorRequestFailed('Unable to retrieve element list ' . $type);
     }
     $xml = $response->getXml();
     $complete = isset($xml->uploader->ticket["complete"]) ? (string) $xml->uploader->ticket["complete"] : null;
     if ($complete) {
         if ((int) $complete == 0) {
             $return["status"] = self::UPLOAD_STATE_NOT_COMPLETED;
         } elseif ((int) $complete == 2) {
             $return["status"] = self::UPLOAD_STATE_FAILED_CONVERTING;
         } else {
             $return["dist_id"] = (string) $xml->uploader->ticket["photoid"];
             $return["status"] = self::UPLOAD_STATE_DONE;
         }
     }
     return $return;
 }
 /**
  * Constructor.
  *
  * You can construct a photoset from an Id or XML.
  *
  * @param   object Phlickr_Api $api This object must have valid
  *          authentication information or an exception will be thrown.
  * @param   mixed $source integer Id, object SimpleXMLElement
  * @throws  Phlickr_Exception, Phlickr_ConnectionException,
  *          Phlickr_XmlParseException
  */
 function __construct(Phlickr_Api $api, $source)
 {
     assert($api->isAuthValid());
     parent::__construct($api, $source);
 }
Beispiel #7
0
 function testGetUserId_WithAuth()
 {
     $api = new Phlickr_Api(TESTING_API_KEY, TESTING_API_SECRET, TESTING_API_TOKEN);
     // ... first the login details (so it can figure out the user id)
     $api->addResponseToCache('flickr.auth.checkToken', $this->api->getParamsForRequest(), TESTING_RESP_OK_PREFIX . TESTING_XML_CHECKTOKEN . TESTING_RESP_SUFIX);
     $this->assertEquals(TESTING_USER_ID, $api->getUserId());
 }
Beispiel #8
0
 /**
  * Create a Phlickr_Request object that will request the XML for this object.
  *
  * @param   object Phlickr_Api $api
  * @param   mixed string $id
  * @return  object Phlickr_Request
  * @see     __construct()
  */
 protected function &createRequest(Phlickr_Api $api, $id)
 {
     $request = $api->createRequest($this->getRequestMethodName(), $this->getRequestMethodParams($id));
     if (is_null($request)) {
         throw new Phlickr_Exception('Could not create a Request.');
     } else {
         return $request;
     }
 }
Beispiel #9
0
 /**
  * Create an Api from settings saved into a file by saveAs().
  *
  * If the file does not exist, is invalid, or cannot be loaded, then you're
  * going to get an exception.
  *
  * The format of the file is:
  * <code>
  * api_key=0123456789abcdef0123456789abcedf
  * api_secret=abcedf0123456789
  * api_token=123-abcdef0123456789
  * cache_file=c:\temp\flickr.tmp
  * </code>
  * The token and cache filename settings are optional. The label of each
  * setting is defined by a constant in this class.
  *
  * @param   string $fileName Name of the file containing the saved Api
  *          settings.
  * @return  object Phlickr_Api
  * @since   0.2.4
  * @see     saveAs()
  * @uses    SETTING_API_KEY Label of the API key setting.
  * @uses    SETTING_API_SECRET Label of the API secret setting.
  * @uses    SETTING_API_TOKEN Label of the API token setting.
  * @uses    SETTING_API_CACHE Label of the cache filename setting.
  * @uses    setCacheFilename() to assign the cache filename if one is
  *          present in the settings file.
  */
 public static function createFrom($filename)
 {
     // create an array for the settings
     $config = array();
     // load the file
     $contents = file_get_contents($filename);
     // parse the key=value pairs into an associative array.
     preg_match_all('/([-_a-zA-Z]+)=(.+)/', $contents, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $config[strtolower($match[1])] = $match[2];
     }
     // build an api object from the settings
     $api = new Phlickr_Api($config[self::SETTING_API_KEY], $config[self::SETTING_API_SECRET], $config[self::SETTING_API_TOKEN]);
     // set the cache filename
     if (isset($config[self::SETTING_API_CACHE])) {
         $api->setCacheFilename($config[self::SETTING_API_CACHE]);
     }
     return $api;
 }
Beispiel #10
0
 /**
  * Find a user based on their Flickr URL.
  *
  * The URL can be in the following forms:
  * - http://flickr.com/photos/39059360@N00/
  * - http://flickr.com/photos/justtesting/
  * - http://flickr.com/people/39059360@N00/
  * - http://flickr.com/people/justtesting/
  *
  * This will thrown an Phlickr_MethodFailureException exception if no user
  * can be found.
  *
  * @param   object Phlickr_Api $api An API object.
  * @param   string $user The user's URL.
  * @return  object Flickr_User
  * @since   0.1.7
  * @see     findByUsername(), findByEmail()
  */
 static function findByUrl(Phlickr_Api $api, $url)
 {
     $resp = $api->executeMethod('flickr.urls.lookupUser', array('url' => $url));
     $id = (string) $resp->xml->user['id'];
     return new Phlickr_User($api, $id);
 }
Beispiel #11
0
 /**
  * Constructor.
  *
  * @param   object Phlickr_Api $api This object must have valid
  *          authentication information or an exception will be thrown.
  */
 function __construct(Phlickr_Api $api)
 {
     assert($api->isAuthValid());
     parent::__construct($api, $api->getUserId());
 }
/**
 * Get a random favorite photo from a Flickr user.
 *
 * @param   string  $userEmail Email address of a Flickr user
 * @return  object Phlickr_Photo
 */
function getRandomFavoritePhoto($userEmail)
{
    $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET);
    // load a saved cache file if it exists, set the expiration limit to a week.
    $api->setCache(Phlickr_Cache::createFrom(CACHE_FILE, 60 * 60 * 24 * 7));
    // select a random favorite photo
    $user = Phlickr_User::findByEmail($api, $userEmail);
    $favlist = $user->getFavoritePhotoList();
    $photo = $favlist->getRandomPhoto();
    assert(!is_null($photo));
    // serialize and save the cache file
    $api->getCache()->saveAs(CACHE_FILE);
    return $photo;
}
Beispiel #13
0
 /**
  * Find a group based on its Flickr URL.
  *
  * The URL can be in the following forms:
  * - http://flickr.com/groups/infrastructure/
  * - http://flickr.com/groups/infrastructure/pool/
  * - http://flickr.com/groups/97544914@N00/
  *
  * This will thrown an Phlickr_MethodFailureException exception if no group
  * can be found.
  *
  * @param   object Phlickr_Api An API object.
  * @param   string The groups's URL.
  * @return  object Flickr_User
  * @since   0.1.8
  */
 static function findByUrl(Phlickr_Api $api, $url)
 {
     $resp = $api->executeMethod('flickr.urls.lookupGroup', array('url' => $url));
     $id = (string) $resp->xml->{self::XML_RESPONSE_ELEMENT}['id'];
     return new Phlickr_Group($api, $id);
 }
 * @version $Id$
 * @author  Andrew Morton <drewish@katherinehouse.com>
 * @license http://opensource.org/licenses/lgpl-license.php
 *          GNU Lesser General Public License, Version 2.1
 */
// use the GetToken.php script to generate a config file.
define('API_CONFIG_FILE', dirname(__FILE__) . './authinfo.cfg');
// the cache file isn't required but if you share it's nice.
define('CACHE_FILE', dirname(__FILE__) . '/cache.tmp');
require_once 'Phlickr/Api.php';
require_once 'Phlickr/PhotoList.php';
require_once 'Phlickr/PhotoListIterator.php';
print "This script lets you select photos by tag and then set the taken date\n";
print "to a month-year date.\n\n";
// set up the api connection
$api = Phlickr_Api::createFrom(API_CONFIG_FILE);
$api->setCacheFilename(CACHE_FILE);
if (!$api->isAuthValid()) {
    die("invalid flickr logon");
}
// get a list of tags
print 'Enter a comma separated list of tags: ';
$tags = trim(fgets(STDIN));
// create a request to search for your photos with the tags.
$request = $api->createRequest('flickr.photos.search', array('tags' => $tags, 'tag_mode' => 'all', 'user_id' => $api->getUserId()));
// use the photo list to parse the search results
print "Searching for matching photos tagged with '{$tags}'...\n";
$pl = new Phlickr_PhotoList($request, Phlickr_PhotoList::PER_PAGE_MAX);
print "Found {$pl->getCount()} photos.\n";
print 'Year: ';
$year = (int) trim(fgets(STDIN));
Beispiel #15
0
 *
 * @version $Id$
 * @author  Andrew Morton <drewish@katherinehouse.com>
 * @license http://opensource.org/licenses/lgpl-license.php
 *          GNU Lesser General Public License, Version 2.1
 */
print "This script will help you retrieve a Flickr authorization token.\n\n";
// Prevent PHP from enforcing a time limit on this script
set_time_limit(0);
// Get the user's API key and secret.
print 'API Key: ';
$api_key = trim(fgets(STDIN));
print 'API Secret: ';
$api_secret = trim(fgets(STDIN));
// Create an API object, then request a frob.
$api = new Phlickr_Api($api_key, $api_secret);
$frob = $api->requestFrob();
print "Got a frob: {$frob}\n";
// Find out the desired permissions.
print 'Permissions (read, write, or delete): ';
$perms = trim(fgets(STDIN));
// Build the authentication URL.
$url = $api->buildAuthUrl($perms, $frob);
print "\nOpen the following URL in your browser and and authorize:\n{$url}\n\n";
print "Press return when you're finished...\n";
fgets(STDIN);
// After they've granted permission, convert the frob to a token.
$token = $api->setAuthTokenFromFrob($frob);
// Print out the token.
print "Auth token: {$token}\n";
// Optionally, create a config file.
Beispiel #16
0
function getApi()
{
    // set up the api connection
    $api = Phlickr_Api::createFrom(API_CONFIG_FILE);
    if (!$api->isAuthValid()) {
        die("invalid flickr logon");
    }
    return $api;
}