├── examples ├── Agateware_Example.JPG ├── config.dist.php ├── unauthenticated_requests.php ├── caching.php ├── uploads.php ├── recent_photos.php └── get_auth_token.php ├── src ├── FlickrException.php ├── ApiMethodGroup.php ├── CommonsApi.php ├── PhotosUploadApi.php ├── ProfileApi.php ├── PhotosTransformApi.php ├── ReflectionApi.php ├── CamerasApi.php ├── TestApi.php ├── CollectionsApi.php ├── PhotosLicensesApi.php ├── GroupsMembersApi.php ├── InterestingnessApi.php ├── ActivityApi.php ├── BlogsApi.php ├── PhotosetsCommentsApi.php ├── GroupsDiscussTopicsApi.php ├── PhotosNotesApi.php ├── Oauth │ └── PhpFlickrService.php ├── PandaApi.php ├── PrefsApi.php ├── Util.php ├── PhotosSuggestionsApi.php ├── PhotosPeopleApi.php ├── ContactsApi.php ├── GroupsDiscussRepliesApi.php ├── PhotosCommentsApi.php ├── GroupsPoolsApi.php ├── MachinetagsApi.php ├── GroupsApi.php ├── UrlsApi.php ├── TagsApi.php ├── Uploader.php ├── FavoritesApi.php ├── PushApi.php ├── TestimonialsApi.php ├── PhotosGeoApi.php ├── PeopleApi.php └── PhotosetsApi.php ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── .phan ├── config.php └── baseline.php ├── phpunit.xml.dist ├── tests ├── UtilTest.php ├── ApiMethodGroup │ ├── TestApiTest.php │ ├── PhotosetsApiTest.php │ ├── UrlsApiTest.php │ └── PhotosApiTest.php └── TestCase.php ├── phpcs.xml ├── composer.json ├── bin └── reflect.php └── README.md /examples/Agateware_Example.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samwilson/phpflickr/HEAD/examples/Agateware_Example.JPG -------------------------------------------------------------------------------- /src/FlickrException.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'src', 6 | 'vendor', 7 | ], 8 | 'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@', 9 | 'exclude_analysis_directory_list' => [ 10 | 'vendor/' 11 | ], 12 | ]; 13 | -------------------------------------------------------------------------------- /src/ApiMethodGroup.php: -------------------------------------------------------------------------------- 1 | flickr = $flickr; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | tests 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/UtilTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('public', Util::getPrivacyLevelById(Util::PRIVACY_PUBLIC)); 12 | $this->assertEquals('friends', Util::getPrivacyLevelById(Util::PRIVACY_FRIENDS)); 13 | $this->assertEquals(false, Util::getPrivacyLevelById(-12)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/CommonsApi.php: -------------------------------------------------------------------------------- 1 | flickr->request('flickr.commons.getInstitutions'); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/config.dist.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | ./ 9 | ./cache/* 10 | ./vendor/* 11 | ./docs/* 12 | ./tests/config.php 13 | 14 | 15 | 16 | 17 | 18 | 19 | ./examples/* 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/PhotosUploadApi.php: -------------------------------------------------------------------------------- 1 | $tickets 20 | ]; 21 | return $this->flickr->request('flickr.photos.upload.checkTickets', $params); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ProfileApi.php: -------------------------------------------------------------------------------- 1 | $userId 20 | ]; 21 | return $this->flickr->request('flickr.profile.getProfile', $params); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/PhotosTransformApi.php: -------------------------------------------------------------------------------- 1 | $photoId, 22 | 'degrees' => $degrees 23 | ]; 24 | return $this->flickr->request('flickr.photos.transform.rotate', $params); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/unauthenticated_requests.php: -------------------------------------------------------------------------------- 1 | photos()->getRecent(['url_s'], 10); 25 | 26 | print_r($recent); 27 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | strategy: 9 | matrix: 10 | os: [ ubuntu-latest, macos-latest, windows-latest ] 11 | # All supported PHP versions https://www.php.net/supported-versions.php 12 | php: [ '8.2','8.3','8.4' ] 13 | 14 | runs-on: ${{matrix.os}} 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v1 19 | 20 | - name: Set up PHP 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: ${{matrix.php}} 24 | extensions: fileinfo, json, pdo, mbstring 25 | 26 | - name: Install 27 | run: | 28 | composer install 29 | 30 | - name: Test 31 | run: | 32 | composer test 33 | env: 34 | FLICKR_API_KEY: ${{ secrets.FLICKR_API_KEY }} 35 | FLICKR_API_SECRET: ${{ secrets.FLICKR_API_SECRET }} 36 | FLICKR_ACCESS_TOKEN: ${{ secrets.FLICKR_ACCESS_TOKEN }} 37 | FLICKR_ACCESS_SECRET: ${{ secrets.FLICKR_ACCESS_SECRET }} 38 | -------------------------------------------------------------------------------- /tests/ApiMethodGroup/TestApiTest.php: -------------------------------------------------------------------------------- 1 | test()->testEcho(); 21 | } 22 | 23 | /** 24 | * Echo returns whatever you send it. 25 | */ 26 | public function testEcho() 27 | { 28 | $flickr = $this->getFlickr(); 29 | 30 | try { 31 | $echo = $flickr->test()->testEcho(['foo' => 'bar']); 32 | } catch (FlickrException $e) { 33 | static::markTestSkipped($e->getMessage()); 34 | } 35 | 36 | $this->assertArrayHasKey('foo', $echo); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/ReflectionApi.php: -------------------------------------------------------------------------------- 1 | $methodName 20 | ]; 21 | return $this->flickr->request('flickr.reflection.getMethodInfo', $params); 22 | } 23 | 24 | /** 25 | * Returns a list of available flickr API methods. 26 | * 27 | * This method does not require authentication. 28 | * 29 | * @link https://www.flickr.com/services/api/flickr.reflection.getMethods.html 30 | * 31 | * @return 32 | */ 33 | public function getMethods() 34 | { 35 | return $this->flickr->request('flickr.reflection.getMethods'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CamerasApi.php: -------------------------------------------------------------------------------- 1 | $brand 21 | ]; 22 | return $this->flickr->request('flickr.cameras.getBrandModels', $params); 23 | } 24 | 25 | /** 26 | * Returns all the brands of cameras that Flickr knows about. 27 | * 28 | * This method does not require authentication. 29 | * 30 | * @link https://www.flickr.com/services/api/flickr.cameras.getBrands.html 31 | * 32 | * @return 33 | */ 34 | public function getBrands() 35 | { 36 | return $this->flickr->request('flickr.cameras.getBrands'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "samwilson/phpflickr", 3 | "description": "A PHP wrapper for the Flickr API, including Oauth.", 4 | "type": "library", 5 | "license": "GPL-3.0-or-later", 6 | "autoload": { 7 | "psr-4": { 8 | "Samwilson\\PhpFlickr\\": "src/" 9 | } 10 | }, 11 | "autoload-dev": { 12 | "psr-4": { 13 | "Samwilson\\PhpFlickr\\Tests\\": "tests/" 14 | } 15 | }, 16 | "require": { 17 | "php": "^8.2", 18 | "ext-curl": "*", 19 | "ext-json": "*", 20 | "ext-libxml": "*", 21 | "ext-simplexml": "*", 22 | "carlos-mg89/oauth": "^0.8", 23 | "psr/cache": "^1.0|^2.0|^3.0" 24 | }, 25 | "require-dev": { 26 | "squizlabs/php_codesniffer": "^3.0", 27 | "mediawiki/minus-x": "^0.3 || ^1.0", 28 | "phpunit/phpunit": "^9.5", 29 | "symfony/cache": "^5.4|^6.4|^7.0", 30 | "symfony/var-dumper": "^5.4|^6.4|^7.0", 31 | "php-parallel-lint/php-parallel-lint": "^1.3", 32 | "phan/phan": "^5.4" 33 | }, 34 | "scripts": { 35 | "phan": "phan --allow-polyfill-parser --load-baseline .phan/baseline.php", 36 | "test": [ 37 | "composer validate", 38 | "parallel-lint . --exclude node_modules --exclude vendor", 39 | "minus-x check . -q", 40 | "phpcs -sp", 41 | "@phan", 42 | "phpunit", 43 | "git status | grep 'nothing to commit, working tree clean'" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/caching.php: -------------------------------------------------------------------------------- 1 | setCache($cache); 27 | 28 | // Now send the same requests, and the second of them should be much faster. 29 | echo "With caching:\n"; 30 | sendRequests($flickr); 31 | 32 | /** 33 | * Send three test requests and output their execution time. 34 | * @param \Samwilson\PhpFlickr\PhpFlickr $flickr 35 | */ 36 | function sendRequests(\Samwilson\PhpFlickr\PhpFlickr $flickr) 37 | { 38 | for ($i = 1; $i <= 3; $i++) { 39 | $start = microtime(true); 40 | $flickr->request('flickr.test.echo'); 41 | echo " $i. " . number_format(microtime(true) - $start, 3) . "\n"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/ApiMethodGroup/PhotosetsApiTest.php: -------------------------------------------------------------------------------- 1 | getFlickr(true); 15 | $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; 16 | $uploaded = $flickr->uploader()->upload($testFilename); 17 | $this->testPhotoId = $uploaded['photoid']; 18 | } 19 | 20 | public function tearDown(): void 21 | { 22 | $this->getFlickr(true)->photos()->delete($this->testPhotoId); 23 | } 24 | 25 | public function testCreate() 26 | { 27 | $flickr = $this->getFlickr(true); 28 | $photoset = $flickr->photosets()->create('Test album', 'The description.', $this->testPhotoId); 29 | static::assertEquals(['id', 'url'], array_keys($photoset)); 30 | $photos = $flickr->photosets()->getPhotos($photoset['id']); 31 | static::assertCount(1, $photos['photo']); 32 | static::assertEquals($this->testPhotoId, $photos['photo'][0]['id']); 33 | } 34 | 35 | public function testAddPhotoToNoneExistantPhotoset() 36 | { 37 | static::expectExceptionMessage('Photoset not found'); 38 | $this->getFlickr(true)->photosets()->addPhoto('xxx', $this->testPhotoId); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/TestApi.php: -------------------------------------------------------------------------------- 1 | flickr->request('flickr.test.echo', $args, true); 21 | } 22 | 23 | /** 24 | * A testing method which checks if the caller is logged in then returns their details. 25 | * This method requires authentication. 26 | * @link https://www.flickr.com/services/api/flickr.test.login.html 27 | * @return string[]|bool An array with 'id', 'username' and 'path_alias' keys, 28 | * or false if unable to log in. 29 | */ 30 | public function login() 31 | { 32 | try { 33 | $response = $this->flickr->request('flickr.test.login', [], true); 34 | return isset($response['user']) ? $response['user'] : false; 35 | } catch (TokenResponseException $exception) { 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/uploads.php: -------------------------------------------------------------------------------- 1 | setAccessToken($accessToken); 16 | $token->setAccessTokenSecret($accessTokenSecret); 17 | $storage = new \OAuth\Common\Storage\Memory(); 18 | $storage->storeAccessToken('Flickr', $token); 19 | 20 | // Create PhpFlickr. 21 | $phpFlickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret); 22 | 23 | // Give PhpFlickr the storage containing the access token. 24 | $phpFlickr->setOauthStorage($storage); 25 | 26 | // Make a request. 27 | $description = 'An example of agate pottery. By Anonymouse512. 28 | Via Wikimedia Commons: https://commons.wikimedia.org/wiki/File:Agateware_Example.JPG'; 29 | $result = $phpFlickr->uploader()->upload( 30 | __DIR__ . '/Agateware_Example.JPG', 31 | 'Test photo', 32 | $description, 33 | 'Agateware pots', 34 | true, 35 | true, 36 | true 37 | ); 38 | if ($result['stat'] === 'fail') { 39 | echo $result['message'] . "\n"; 40 | } else { 41 | $info = $phpFlickr->photos()->getInfo($result['photoid']); 42 | echo "The new photo is: " . $info['urls']['url'][0]['_content'] . "\n"; 43 | } 44 | -------------------------------------------------------------------------------- /src/CollectionsApi.php: -------------------------------------------------------------------------------- 1 | $collectionId 21 | ]; 22 | return $this->flickr->request('flickr.collections.getInfo', $params); 23 | } 24 | 25 | /** 26 | * Returns a tree (or sub tree) of collections belonging to a given user. 27 | * 28 | * This method does not require authentication. 29 | * 30 | * @link https://www.flickr.com/services/api/flickr.collections.getTree.html 31 | * @param string $collectionId The ID of the collection to fetch a tree for, or 32 | * zero to fetch the root collection. Defaults to zero. 33 | * @param string $userId The ID of the account to fetch the collection tree for. 34 | * Deafults to the calling user. 35 | * @return 36 | */ 37 | public function getTree($collectionId = null, $userId = null) 38 | { 39 | $params = [ 40 | 'collection_id' => $collectionId, 41 | 'user_id' => $userId 42 | ]; 43 | return $this->flickr->request('flickr.collections.getTree', $params); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhotosLicensesApi.php: -------------------------------------------------------------------------------- 1 | flickr->request('flickr.photos.licenses.getInfo'); 18 | $licenseData = $response ? $response['licenses']['license'] : []; 19 | foreach ($licenseData as $license) { 20 | $licenses[$license['id']] = $license; 21 | } 22 | return $licenses; 23 | } 24 | 25 | /** 26 | * Sets the license for a photo. This method requires authentication with 'write' permission. 27 | * @link https://www.flickr.com/services/api/flickr.photos.licenses.setLicense.html 28 | * @param int $photoId The photo to update the license for. 29 | * @param int $licenseId The license to apply, or 0 (zero) to remove the current license. Note 30 | * that the "no known copyright restrictions" license (7) is not a valid argument. 31 | * @return bool 32 | */ 33 | public function setLicense($photoId, $licenseId) 34 | { 35 | $method = 'flickr.photos.licenses.setLicense'; 36 | $params = ['photo_id' => $photoId, 'license_id' => $licenseId]; 37 | return $this->flickr->request($method, $params, true); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/GroupsMembersApi.php: -------------------------------------------------------------------------------- 1 |
  • 2: 18 | * member
  • 3: moderator
  • 4: admin
  • By default returns all 19 | * types. (Returning super rare member type "1: narwhal" isn't supported by this 20 | * API method) 21 | * @param string $perPage Number of members to return per page. If this argument is 22 | * omitted, it defaults to 100. The maximum allowed value is 500. 23 | * @param string $page The page of results to return. If this argument is omitted, 24 | * it defaults to 1. 25 | * @return 26 | */ 27 | public function getList($groupId, $membertypes = null, $perPage = null, $page = null) 28 | { 29 | $params = [ 30 | 'group_id' => $groupId, 31 | 'membertypes' => $membertypes, 32 | 'per_page' => $perPage, 33 | 'page' => $page 34 | ]; 35 | return $this->flickr->request('flickr.groups.members.getList', $params); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/InterestingnessApi.php: -------------------------------------------------------------------------------- 1 | description, 18 | * license, date_upload, date_taken, 19 | * owner_name, icon_server, original_format, 20 | * last_update, geo, tags, 21 | * machine_tags, o_dims, views, 22 | * media, path_alias, url_sq, 23 | * url_t, url_s, url_q, url_m, 24 | * url_n, url_z, url_c, url_l, 25 | * url_o 26 | * @param string $perPage Number of photos to return per page. If this argument is 27 | * omitted, it defaults to 100. The maximum allowed value is 500. 28 | * @param string $page The page of results to return. If this argument is omitted, 29 | * it defaults to 1. 30 | * @return 31 | */ 32 | public function getList($date = null, $extras = null, $perPage = null, $page = null) 33 | { 34 | $params = [ 35 | 'date' => $date, 36 | 'extras' => $extras, 37 | 'per_page' => $perPage, 38 | 'page' => $page 39 | ]; 40 | return $this->flickr->request('flickr.interestingness.getList', $params); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/recent_photos.php: -------------------------------------------------------------------------------- 1 | setAccessToken($accessToken); 28 | $token->setAccessTokenSecret($accessTokenSecret); 29 | $storage = new \OAuth\Common\Storage\Memory(); 30 | $storage->storeAccessToken('Flickr', $token); 31 | 32 | // Create PhpFlickr. 33 | $phpFlickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret); 34 | 35 | // Give PhpFlickr the storage containing the access token. 36 | $phpFlickr->setOauthStorage($storage); 37 | 38 | // Make a request. 39 | $recent = $phpFlickr->photos()->getRecent([], 10); 40 | 41 | // Display a list of photo titles. 42 | echo ''; 53 | -------------------------------------------------------------------------------- /tests/ApiMethodGroup/UrlsApiTest.php: -------------------------------------------------------------------------------- 1 | getFlickr(); 16 | static::assertEquals($url, $flickr->urls()->getImageUrl($photoInfo, $size)); 17 | } 18 | 19 | public function provideGetImageUrl() 20 | { 21 | // URL forms: 22 | // https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg 23 | // https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg 24 | // https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png) 25 | return [ 26 | 'medium is default' => [ 27 | ['farm' => 'F', 'server' => 'S', 'id' => 'I', 'secret' => 'Q'], 28 | '', 29 | 'https://farmF.staticflickr.com/S/I_Q.jpg', 30 | ], 31 | 'old size name for medium' => [ 32 | ['farm' => 'F', 'server' => 'S', 'id' => 'I', 'secret' => 'Q'], 33 | 'medium', 34 | 'https://farmF.staticflickr.com/S/I_Q.jpg', 35 | ], 36 | 'old size name for square' => [ 37 | ['farm' => 'F', 'server' => 'S', 'id' => 'I', 'secret' => 'Q'], 38 | 'square', 39 | 'https://farmF.staticflickr.com/S/I_Q_s.jpg', 40 | ], 41 | 'original' => [ 42 | [ 43 | 'farm' => 'F', 'server' => 'S', 'id' => 'I', 'secret' => 'Q', 44 | 'originalsecret' => 'OQ', 'originalformat' => 'OF' 45 | ], 46 | PhotosApi::SIZE_ORIGINAL, 47 | 'https://farmF.staticflickr.com/S/I_OQ_o.OF', 48 | ], 49 | 'large size' => [ 50 | ['farm' => 'F', 'server' => 'S', 'id' => 'I', 'secret' => 'Q'], 51 | PhotosApi::SIZE_LARGE_1600, 52 | 'https://farmF.staticflickr.com/S/I_Q_h.jpg', 53 | ], 54 | ]; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ActivityApi.php: -------------------------------------------------------------------------------- 1 | Do not poll this method more than once an hour. 10 | * 11 | * This method requires authentication. 12 | * 13 | * @link https://www.flickr.com/services/api/flickr.activity.userComments.html 14 | * @param string $perPage Number of items to return per page. If this argument is 15 | * omitted, it defaults to 10. The maximum allowed value is 50. 16 | * @param string $page The page of results to return. If this argument is omitted, 17 | * it defaults to 1. 18 | * @return array 19 | */ 20 | public function userComments($perPage = null, $page = null) 21 | { 22 | $params = [ 23 | 'per_page' => $perPage, 24 | 'page' => $page 25 | ]; 26 | return $this->flickr->request('flickr.activity.userComments', $params); 27 | } 28 | 29 | /** 30 | * Returns a list of recent activity on photos belonging to the calling user. Do 31 | * not poll this method more than once an hour. 32 | * 33 | * This method requires authentication. 34 | * 35 | * @link https://www.flickr.com/services/api/flickr.activity.userPhotos.html 36 | * @param string $timeframe The timeframe in which to return updates for. This can 37 | * be specified in days ('2d') or hours ('4h'). The 38 | * default behavoir is to return changes since the beginning of the previous user 39 | * session. 40 | * @param string $perPage Number of items to return per page. If this argument is 41 | * omitted, it defaults to 10. The maximum allowed value is 50. 42 | * @param string $page The page of results to return. If this argument is omitted, 43 | * it defaults to 1. 44 | * @return array 45 | */ 46 | public function userPhotos($timeframe = null, $perPage = null, $page = null) 47 | { 48 | $params = [ 49 | 'timeframe' => $timeframe, 50 | 'per_page' => $perPage, 51 | 'page' => $page 52 | ]; 53 | return $this->flickr->request('flickr.activity.userPhotos', $params); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/get_auth_token.php: -------------------------------------------------------------------------------- 1 | setOauthStorage($storage); 29 | 30 | if (!isset($_GET['oauth_token'])) { 31 | $callbackHere = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 32 | $url = $flickr->getAuthUrl('delete', $callbackHere); 33 | echo "$url"; 34 | } 35 | 36 | if (isset($_GET['oauth_token'])) { 37 | $accessToken = $flickr->retrieveAccessToken($_GET['oauth_verifier'], $_GET['oauth_token']); 38 | } 39 | } else { 40 | /* 41 | * The CLI workflow. 42 | */ 43 | $storage = new \OAuth\Common\Storage\Memory(); 44 | $flickr->setOauthStorage($storage); 45 | 46 | $url = $flickr->getAuthUrl('delete'); 47 | echo "Go to $url\nEnter access code: "; 48 | $code = fgets(STDIN); 49 | $verifier = preg_replace('/[^0-9]/', '', $code); 50 | $accessToken = $flickr->retrieveAccessToken($verifier); 51 | } 52 | 53 | if (isset($accessToken) && $accessToken instanceof \OAuth\Common\Token\TokenInterface) { 54 | /* 55 | * You should save the access token and its secret somewhere safe. 56 | */ 57 | echo '$accessToken = "' . $accessToken->getAccessToken() . '";' . PHP_EOL; 58 | echo '$accessTokenSecret = "' . $accessToken->getAccessTokenSecret() . '";' . PHP_EOL; 59 | 60 | /* 61 | * Any methods can now be called. 62 | */ 63 | $login = $flickr->test()->login(); 64 | echo "You are authenticated as: {$login['username']}\n"; 65 | } 66 | -------------------------------------------------------------------------------- /src/BlogsApi.php: -------------------------------------------------------------------------------- 1 | flickr.blogs.getServices(). 16 | * @return array 17 | */ 18 | public function getList($service = null) 19 | { 20 | $params = [ 21 | 'service' => $service 22 | ]; 23 | return $this->flickr->request('flickr.blogs.getList', $params); 24 | } 25 | 26 | /** 27 | * Return a list of Flickr supported blogging services 28 | * 29 | * This method does not require authentication. 30 | * 31 | * @link https://www.flickr.com/services/api/flickr.blogs.getServices.html 32 | * 33 | * @return array 34 | */ 35 | public function getServices() 36 | { 37 | return $this->flickr->request('flickr.blogs.getServices'); 38 | } 39 | 40 | /** 41 | * This method requires authentication. 42 | * 43 | * @link https://www.flickr.com/services/api/flickr.blogs.postPhoto.html 44 | * @param string $photoId The id of the photo to blog 45 | * @param string $title The blog post title 46 | * @param string $description The blog post body 47 | * @param string $blogPassword The password for the blog (used when the blog does 48 | * not have a stored password). 49 | * @param string $service A Flickr supported blogging service. Instead of passing 50 | * a blog id you can pass a service id and we'll post to the first blog of that 51 | * service we find. 52 | * @param string $blogId The id of the blog to post to. 53 | * @return array 54 | */ 55 | public function postPhoto($photoId, $title, $description, $blogPassword = null, $service = null, $blogId = null) 56 | { 57 | $params = [ 58 | 'blog_id' => $blogId, 59 | 'photo_id' => $photoId, 60 | 'title' => $title, 61 | 'description' => $description, 62 | 'blog_password' => $blogPassword, 63 | 'service' => $service 64 | ]; 65 | return $this->flickr->request('flickr.blogs.postPhoto', $params); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/PhotosetsCommentsApi.php: -------------------------------------------------------------------------------- 1 | $photosetId, 21 | 'comment_text' => $commentText 22 | ]; 23 | return $this->flickr->request('flickr.photosets.comments.addComment', $params); 24 | } 25 | 26 | /** 27 | * Delete a photoset comment as the currently authenticated user. 28 | * 29 | * This method requires authentication. 30 | * 31 | * @link https://www.flickr.com/services/api/flickr.photosets.comments.deleteComment.html 32 | * @param string $commentId The id of the comment to delete from a photoset. 33 | * @return 34 | */ 35 | public function deleteComment($commentId) 36 | { 37 | $params = [ 38 | 'comment_id' => $commentId 39 | ]; 40 | return $this->flickr->request('flickr.photosets.comments.deleteComment', $params); 41 | } 42 | 43 | /** 44 | * Edit the text of a comment as the currently authenticated user. 45 | * 46 | * This method requires authentication. 47 | * 48 | * @link https://www.flickr.com/services/api/flickr.photosets.comments.editComment.html 49 | * @param string $commentId The id of the comment to edit. 50 | * @param string $commentText Update the comment to this text. 51 | * @return 52 | */ 53 | public function editComment($commentId, $commentText) 54 | { 55 | $params = [ 56 | 'comment_id' => $commentId, 57 | 'comment_text' => $commentText 58 | ]; 59 | return $this->flickr->request('flickr.photosets.comments.editComment', $params); 60 | } 61 | 62 | /** 63 | * Returns the comments for a photoset. 64 | * 65 | * This method does not require authentication. 66 | * 67 | * @link https://www.flickr.com/services/api/flickr.photosets.comments.getList.html 68 | * @param string $photosetId The id of the photoset to fetch comments for. 69 | * @return 70 | */ 71 | public function getList($photosetId) 72 | { 73 | $params = [ 74 | 'photoset_id' => $photosetId 75 | ]; 76 | return $this->flickr->request('flickr.photosets.comments.getList', $params); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/GroupsDiscussTopicsApi.php: -------------------------------------------------------------------------------- 1 | $groupId, 22 | 'subject' => $subject, 23 | 'message' => $message 24 | ]; 25 | return $this->flickr->request('flickr.groups.discuss.topics.add', $params); 26 | } 27 | 28 | /** 29 | * Get information about a group discussion topic. 30 | * 31 | * This method does not require authentication. 32 | * 33 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.topics.getInfo.html 34 | * @param string $groupId NSID or group alias of the group to which the topic 35 | * belongs. Making this parameter optional for legacy reasons, but it is highly 36 | * recommended to pass this in to get better performance. 37 | * @param string $topicId The ID for the topic to edit. 38 | * @return 39 | */ 40 | public function getInfo($groupId, $topicId) 41 | { 42 | $params = [ 43 | 'group_id' => $groupId, 44 | 'topic_id' => $topicId 45 | ]; 46 | return $this->flickr->request('flickr.groups.discuss.topics.getInfo', $params); 47 | } 48 | 49 | /** 50 | * Get a list of discussion topics in a group. 51 | * 52 | * This method does not require authentication. 53 | * 54 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.topics.getList.html 55 | * @param string $groupId The NSID or path alias of the group to fetch information 56 | * for. 57 | * @param string $perPage Number of photos to return per page. If this argument is 58 | * omitted, it defaults to 100. The maximum allowed value is 500. 59 | * @param string $page The page of results to return. If this argument is omitted, 60 | * it defaults to 1. 61 | * @return 62 | */ 63 | public function getList($groupId, $perPage = null, $page = null) 64 | { 65 | $params = [ 66 | 'group_id' => $groupId, 67 | 'per_page' => $perPage, 68 | 'page' => $page 69 | ]; 70 | return $this->flickr->request('flickr.groups.discuss.topics.getList', $params); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/PhotosNotesApi.php: -------------------------------------------------------------------------------- 1 | $photoId, 26 | 'note_x' => $noteX, 27 | 'note_y' => $noteY, 28 | 'note_w' => $noteW, 29 | 'note_h' => $noteH, 30 | 'note_text' => $noteText 31 | ]; 32 | return $this->flickr->request('flickr.photos.notes.add', $params); 33 | } 34 | 35 | /** 36 | * Delete a note from a photo. 37 | * 38 | * This method requires authentication. 39 | * 40 | * @link https://www.flickr.com/services/api/flickr.photos.notes.delete.html 41 | * @param string $noteId The id of the note to delete 42 | * @return 43 | */ 44 | public function delete($noteId) 45 | { 46 | $params = [ 47 | 'note_id' => $noteId 48 | ]; 49 | return $this->flickr->request('flickr.photos.notes.delete', $params); 50 | } 51 | 52 | /** 53 | * Edit a note on a photo. Coordinates and sizes are in pixels, based on the 500px 54 | * image size shown on individual photo pages. 55 | 56 | * 57 | * This method requires authentication. 58 | * 59 | * @link https://www.flickr.com/services/api/flickr.photos.notes.edit.html 60 | * @param string $noteId The id of the note to edit 61 | * @param string $noteX The left coordinate of the note 62 | * @param string $noteY The top coordinate of the note 63 | * @param string $noteW The width of the note 64 | * @param string $noteH The height of the note 65 | * @param string $noteText The description of the note 66 | * @return 67 | */ 68 | public function edit($noteId, $noteX, $noteY, $noteW, $noteH, $noteText) 69 | { 70 | $params = [ 71 | 'note_id' => $noteId, 72 | 'note_x' => $noteX, 73 | 'note_y' => $noteY, 74 | 'note_w' => $noteW, 75 | 'note_h' => $noteH, 76 | 'note_text' => $noteText 77 | ]; 78 | return $this->flickr->request('flickr.photos.notes.edit', $params); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | flickrs[$authed])) { 25 | return $this->flickrs[$authed]; 26 | } 27 | 28 | // Get config values from env vars or the tests/config.php file. 29 | $apiKey = getenv('FLICKR_API_KEY'); 30 | $apiSecret = getenv('FLICKR_API_SECRET'); 31 | $accessToken = getenv('FLICKR_ACCESS_TOKEN'); 32 | $accessTokenSecret = getenv('FLICKR_ACCESS_SECRET'); 33 | $configFile = __DIR__ . '/config.php'; 34 | if (empty($apiKey) && file_exists($configFile)) { 35 | require $configFile; 36 | } 37 | if (empty($apiKey)) { 38 | // Skip if no key found, so PRs from forks can still be run in CI. 39 | static::markTestSkipped('No Flickr API key set (in either the FLICKR_* env vars or ' . $configFile . ')'); 40 | } 41 | try { 42 | $this->flickrs[$authed] = new PhpFlickr($apiKey, $apiSecret); 43 | } catch (FlickrException $ex) { 44 | static::markTestSkipped($ex->getMessage()); 45 | } 46 | 47 | // Authenticate? 48 | if ($authenticate && !empty($accessToken) && !empty($accessTokenSecret)) { 49 | $token = new StdOAuth1Token(); 50 | $token->setAccessToken($accessToken); 51 | $token->setAccessTokenSecret($accessTokenSecret); 52 | $this->flickrs[$authed]->getOauthTokenStorage()->storeAccessToken('Flickr', $token); 53 | try { 54 | $authenticated = $this->flickrs[$authed]->test()->login(); 55 | } catch (FlickrException $e) { 56 | $authenticated = false; 57 | } 58 | if (!$authenticated) { 59 | static::markTestSkipped('Unable to authenticate with provided access token.'); 60 | } 61 | } 62 | if ($authenticate && empty($accessToken)) { 63 | static::markTestSkipped( 64 | 'Access token required for this test. ' 65 | . 'Please use examples/get_auth_token.php to get token to add to tests/config.php.' 66 | ); 67 | } 68 | 69 | return $this->flickrs[$authed]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /.phan/baseline.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'src/CamerasApi.php' => ['PhanUnextractableAnnotation'], 6 | 'src/CollectionsApi.php' => ['PhanUnextractableAnnotation'], 7 | 'src/CommonsApi.php' => ['PhanUnextractableAnnotation'], 8 | 'src/ContactsApi.php' => ['PhanUnextractableAnnotation'], 9 | 'src/FavoritesApi.php' => ['PhanUnextractableAnnotation'], 10 | 'src/GalleriesApi.php' => ['PhanTypeMismatchDefault', 'PhanUnextractableAnnotation'], 11 | 'src/GroupsApi.php' => ['PhanUnextractableAnnotation'], 12 | 'src/GroupsDiscussRepliesApi.php' => ['PhanUnextractableAnnotation'], 13 | 'src/GroupsDiscussTopicsApi.php' => ['PhanUnextractableAnnotation'], 14 | 'src/GroupsMembersApi.php' => ['PhanUnextractableAnnotation'], 15 | 'src/GroupsPoolsApi.php' => ['PhanUnextractableAnnotation'], 16 | 'src/InterestingnessApi.php' => ['PhanUnextractableAnnotation'], 17 | 'src/MachinetagsApi.php' => ['PhanUnextractableAnnotation'], 18 | 'src/PandaApi.php' => ['PhanUnextractableAnnotation'], 19 | 'src/PeopleApi.php' => ['PhanUnextractableAnnotation'], 20 | 'src/PhotosApi.php' => ['PhanTypeMismatchDefault', 'PhanTypeMismatchForeach', 'PhanUnextractableAnnotation'], 21 | 'src/PhotosCommentsApi.php' => ['PhanUnextractableAnnotation'], 22 | 'src/PhotosGeoApi.php' => ['PhanUnextractableAnnotation'], 23 | 'src/PhotosNotesApi.php' => ['PhanUnextractableAnnotation'], 24 | 'src/PhotosPeopleApi.php' => ['PhanUnextractableAnnotation'], 25 | 'src/PhotosSuggestionsApi.php' => ['PhanUnextractableAnnotation'], 26 | 'src/PhotosTransformApi.php' => ['PhanUnextractableAnnotation'], 27 | 'src/PhotosUploadApi.php' => ['PhanUnextractableAnnotation'], 28 | 'src/PhotosetsCommentsApi.php' => ['PhanUnextractableAnnotation'], 29 | 'src/PhpFlickr.php' => [ 30 | 'PhanInvalidCommentForDeclarationType', 'PhanTypeConversionFromArray', 'PhanTypeMismatchArgumentInternal', 31 | 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassInstanceof', 32 | 'PhanUndeclaredClassMethod', 'PhanUndeclaredMethod', 'PhanUndeclaredTypeParameter', 33 | 'PhanUndeclaredTypeProperty', 'PhanUndeclaredTypeReturnType', 'PhanUnreferencedUseNormal' 34 | ], 35 | 'src/PlacesApi.php' => ['PhanUnextractableAnnotation'], 36 | 'src/PrefsApi.php' => ['PhanUnextractableAnnotation'], 37 | 'src/PushApi.php' => ['PhanUnextractableAnnotation'], 38 | 'src/ReflectionApi.php' => ['PhanUnextractableAnnotation'], 39 | 'src/StatsApi.php' => ['PhanUnextractableAnnotation'], 40 | 'src/TagsApi.php' => ['PhanUnextractableAnnotation'], 41 | 'src/TestApi.php' => ['PhanUndeclaredClassCatch'], 42 | 'src/TestimonialsApi.php' => ['PhanUnextractableAnnotation'], 43 | 'src/Uploader.php' => [ 44 | 'PhanUndeclaredClassMethod', 'PhanUndeclaredProperty', 45 | 'PhanUndeclaredTypeThrowsType', 'PhanUnreferencedUseNormal' 46 | ], 47 | 'src/Util.php' => ['PhanParamSuspiciousOrder'], 48 | ], 49 | ]; 50 | -------------------------------------------------------------------------------- /src/Oauth/PhpFlickrService.php: -------------------------------------------------------------------------------- 1 | storage->retrieveAccessToken($this->service()); 75 | assert($token instanceof TokenInterface); 76 | $this->signature->setTokenSecret($token->getAccessTokenSecret()); 77 | $authParameters = $this->getBasicAuthorizationHeaderInfo(); 78 | if (isset($authParameters['oauth_callback'])) { 79 | unset($authParameters['oauth_callback']); 80 | } 81 | $authParameters = array_merge($authParameters, ['oauth_token' => $token->getAccessToken()]); 82 | $signatureParams = array_merge($authParameters, $args); 83 | $authParameters['oauth_signature'] = $this->signature->getSignature( 84 | new Uri($uri), 85 | $signatureParams 86 | ); 87 | return array_merge($authParameters, $args); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/PandaApi.php: -------------------------------------------------------------------------------- 1 | Flickr 9 | * pandas, from whom you can request photos using the flickr.panda.getPhotos API 11 | * method. 12 |

    13 | More information about the pandas can be found on the dev 15 | * blog. 16 | * 17 | * This method does not require authentication. 18 | * 19 | * @link https://www.flickr.com/services/api/flickr.panda.getList.html 20 | * 21 | * @return 22 | */ 23 | public function getList() 24 | { 25 | return $this->flickr->request('flickr.panda.getList'); 26 | } 27 | 28 | /** 29 | * Ask the Flickr Pandas for a 30 | * list of recent public (and "safe") photos. 31 |

    32 | More information about the 33 | * pandas can be found on the dev 35 | * blog. 36 | * 37 | * This method does not require authentication. 38 | * 39 | * @link https://www.flickr.com/services/api/flickr.panda.getPhotos.html 40 | * @param string $pandaName The name of the panda to ask for photos from. There are 41 | * currently three pandas named:


    You can fetch a list of all the current 47 | * pandas using the flickr.panda.getList API 49 | * method. 50 | * @param string $extras A comma-delimited list of extra information to fetch for 51 | * each returned record. Currently supported fields are: description, 52 | * license, date_upload, date_taken, 53 | * owner_name, icon_server, original_format, 54 | * last_update, geo, tags, 55 | * machine_tags, o_dims, views, 56 | * media, path_alias, url_sq, 57 | * url_t, url_s, url_q, url_m, 58 | * url_n, url_z, url_c, url_l, 59 | * url_o 60 | * @param string $perPage Number of photos to return per page. If this argument is 61 | * omitted, it defaults to 100. The maximum allowed value is 500. 62 | * @param string $page The page of results to return. If this argument is omitted, 63 | * it defaults to 1. 64 | * @return 65 | */ 66 | public function getPhotos($pandaName, $extras = null, $perPage = null, $page = null) 67 | { 68 | $params = [ 69 | 'panda_name' => $pandaName, 70 | 'extras' => $extras, 71 | 'per_page' => $perPage, 72 | 'page' => $page 73 | ]; 74 | return $this->flickr->request('flickr.panda.getPhotos', $params); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/PrefsApi.php: -------------------------------------------------------------------------------- 1 | flickr->request('flickr.prefs.getContentType'); 19 | } 20 | 21 | /** 22 | * Returns the default privacy level for geographic information attached to the 23 | * user's photos and whether or not the user has chosen to use geo-related EXIF 24 | * information to automatically geotag their photos. 25 | 26 | Possible values, for viewing 27 | * geotagged photos, are: 28 | 29 | 41 | 42 | Users can edit this preference at http://www.flickr.com/account/geo/privacy/. 44 |

    46 | Possible values for whether or not geo-related EXIF information will be 47 | * used to geotag a photo are: 48 | 49 | 55 | 56 | Users can edit this preference at http://www.flickr.com/account/geo/exif/?from=privacy 58 | * 59 | * This method requires authentication. 60 | * 61 | * @link https://www.flickr.com/services/api/flickr.prefs.getGeoPerms.html 62 | * 63 | * @return 64 | */ 65 | public function getGeoPerms() 66 | { 67 | return $this->flickr->request('flickr.prefs.getGeoPerms'); 68 | } 69 | 70 | /** 71 | * Returns the default hidden preference for the user. 72 | * 73 | * This method requires authentication. 74 | * 75 | * @link https://www.flickr.com/services/api/flickr.prefs.getHidden.html 76 | * 77 | * @return 78 | */ 79 | public function getHidden() 80 | { 81 | return $this->flickr->request('flickr.prefs.getHidden'); 82 | } 83 | 84 | /** 85 | * Returns the default privacy level preference for the user. 86 | 87 | Possible values 88 | * are: 89 | 97 | * 98 | * This method requires authentication. 99 | * 100 | * @link https://www.flickr.com/services/api/flickr.prefs.getPrivacy.html 101 | * 102 | * @return 103 | */ 104 | public function getPrivacy() 105 | { 106 | return $this->flickr->request('flickr.prefs.getPrivacy'); 107 | } 108 | 109 | /** 110 | * Returns the default safety level preference for the user. 111 | * 112 | * This method requires authentication. 113 | * 114 | * @link https://www.flickr.com/services/api/flickr.prefs.getSafetyLevel.html 115 | * 116 | * @return 117 | */ 118 | public function getSafetyLevel() 119 | { 120 | return $this->flickr->request('flickr.prefs.getSafetyLevel'); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Util.php: -------------------------------------------------------------------------------- 1 | = $base_count) { 29 | $div = $num / $base_count; 30 | $mod = ($num - ($base_count * intval($div))); 31 | $encoded = static::BASE58_ALPHABET[$mod] . $encoded; 32 | $num = intval($div); 33 | } 34 | 35 | if ($num) { 36 | $encoded = static::BASE58_ALPHABET[$num] . $encoded; 37 | } 38 | 39 | return $encoded; 40 | } 41 | 42 | /** 43 | * Decode a photo ID from Flickr's short-URL base-58 system. 44 | * @link https://www.flickr.com/groups/api/discuss/72157616713786392/ 45 | * @param string $num 46 | * @return bool|int 47 | */ 48 | public static function base58decode($num) 49 | { 50 | $decoded = 0; 51 | $multi = 1; 52 | while (strlen($num) > 0) { 53 | $digit = $num[strlen($num) - 1]; 54 | $decoded += $multi * strpos(static::BASE58_ALPHABET, $digit); 55 | $multi = $multi * strlen(static::BASE58_ALPHABET); 56 | $num = substr($num, 0, -1); 57 | } 58 | return $decoded; 59 | } 60 | 61 | /** 62 | * Get the privacy integer given the three privacy categories. 63 | * @param bool $isPublic 64 | * @param bool $isFriend 65 | * @param bool $isFamily 66 | * @return int 67 | */ 68 | public static function privacyLevel($isPublic, $isFriend, $isFamily) 69 | { 70 | if ($isPublic) { 71 | return static::PRIVACY_PUBLIC; 72 | } 73 | if ($isFriend && $isFamily) { 74 | return static::PRIVACY_FRIENDS_FAMILY; 75 | } 76 | if ($isFriend) { 77 | return static::PRIVACY_FRIENDS; 78 | } 79 | if ($isFamily) { 80 | return static::PRIVACY_FAMILY; 81 | } 82 | return static::PRIVACY_PRIVATE; 83 | } 84 | 85 | /** 86 | * Get all privacy levels. 87 | * @return array 88 | */ 89 | public static function getPrivacyLevels() 90 | { 91 | return [ 92 | 'public' => static::PRIVACY_PUBLIC, 93 | 'friends_family' => static::PRIVACY_FRIENDS_FAMILY, 94 | 'friends' => static::PRIVACY_FRIENDS, 95 | 'family' => static::PRIVACY_FAMILY, 96 | 'private' => static::PRIVACY_PRIVATE, 97 | ]; 98 | } 99 | 100 | /** 101 | * Get the name of a given privacy level. 102 | * @param int $id The value of one of the PRIVACY_* constants. 103 | * @return string|bool The name of the privacy leve, or false if it doesn't exist. 104 | */ 105 | public static function getPrivacyLevelById($id) 106 | { 107 | $privacyLevels = array_flip(static::getPrivacyLevels()); 108 | if (!isset($privacyLevels[$id])) { 109 | return false; 110 | } 111 | return $privacyLevels[$id]; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /bin/reflect.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | __DIR__ . '/../cache' ]); 14 | $pool = new StashPool($driver); 15 | $phpflickr->setCache($pool); 16 | 17 | // Get method info. 18 | $methodsResponse = $phpflickr->reflection()->getMethods(); 19 | $methods = []; 20 | foreach ($methodsResponse as $method) { 21 | $methodParts = explode('.', $method); 22 | $methodGroup = array_slice($methodParts, 1, count($methodParts) - 2); 23 | $methodGroupName = implode('', array_map('ucfirst', $methodGroup)) . 'Api'; 24 | $classname = '\\Samwilson\\PhpFlickr\\' . $methodGroupName; 25 | $methods[$methodGroupName]['classname'] = $classname; 26 | $methods[$methodGroupName]['methods'][$method] = $methodParts[count($methodParts) - 1]; 27 | } 28 | 29 | // Create PHP code. 30 | foreach ($methods as $methodGroupName => $methodInfo) { 31 | $classname = basename(str_replace('\\', '/', $methodInfo['classname'])); 32 | $php = " $shortMethod) { 36 | $details = $phpflickr->reflection()->getMethodInfo($method); 37 | $desc = wordwrap($details['method']['description'], 80, "\n * "); 38 | $auth = $details['method']['needslogin'] ? 'requires' : 'does not require'; 39 | $params = []; 40 | $sigs = []; 41 | $paramNames = []; 42 | foreach ($details['arguments']['argument'] as $arg) { 43 | if ($arg['name'] === 'api_key') { 44 | continue; 45 | } 46 | $nameParts = explode('_', $arg['name']); 47 | $phpName = $nameParts[0] . implode('', array_map('ucfirst', array_slice($nameParts, 1))); 48 | $paramDesc = str_replace("\n", ' ', $arg['_content']); 49 | $params[] = wordwrap('@param string $' . $phpName . ' ' . $paramDesc, 80, "\n * "); 50 | $sigs[] = '$' . $phpName . (isset($arg['optional']) && $arg['optional'] ? ' = null' : ''); 51 | $paramNames[$arg['name']] = "'" . $arg['name'] . "' => \$$phpName"; 52 | } 53 | $url = 'https://www.flickr.com/services/api/' . $method . '.html'; 54 | $methodPhp = " /**\n * $desc\n" 55 | . " *\n" 56 | . " * This method $auth authentication.\n" 57 | . " *\n" 58 | . " * @link $url\n" 59 | . " * " . implode("\n * ", $params) . "\n" 60 | . " * @return\n" 61 | . " */\n" 62 | . " public function " . $shortMethod . "(" . implode(', ', $sigs) . ")\n {\n"; 63 | if (count($params) > 0) { 64 | $methodPhp .= " \$params = [\n" 65 | . " " . implode(",\n ", $paramNames) . "\n" 66 | . " ];\n" 67 | . " return \$this->flickr->request('" . $method . "', \$params);\n"; 68 | } else { 69 | $methodPhp .= " return \$this->flickr->request('" . $method . "');\n"; 70 | } 71 | $methodPhp .= " }\n\n"; 72 | try { 73 | $reflection = new ReflectionClass($methodInfo['classname']); 74 | $reflection->getMethod($shortMethod); 75 | } catch (ReflectionException $exception) { 76 | if ($shortMethod !== 'echo') { 77 | // Don't flag echo() as missing, as it's called "testEcho" in the code. 78 | echo "Not found: " . $methodInfo['classname'] . '::' . $shortMethod . "()\n\n$methodPhp"; 79 | } 80 | } 81 | $php .= $methodPhp; 82 | } 83 | $php .= "}\n"; 84 | 85 | $filename = __DIR__ . '/../src/' . $classname . '.php'; 86 | echo "Writing $filename\n"; 87 | file_put_contents($filename, $php); 88 | } 89 | -------------------------------------------------------------------------------- /src/PhotosSuggestionsApi.php: -------------------------------------------------------------------------------- 1 | $suggestionId 21 | ]; 22 | return $this->flickr->request('flickr.photos.suggestions.approveSuggestion', $params); 23 | } 24 | 25 | /** 26 | * Return a list of suggestions for a user that are pending approval. 27 | * 28 | * This method requires authentication. 29 | * 30 | * @link https://www.flickr.com/services/api/flickr.photos.suggestions.getList.html 31 | * @param string $photoId Only show suggestions for a single photo. 32 | * @param string $statusId Only show suggestions with a given status. The default is pending (or "0"). 35 | * @return 36 | */ 37 | public function getList($photoId = null, $statusId = null) 38 | { 39 | $params = [ 40 | 'photo_id' => $photoId, 41 | 'status_id' => $statusId 42 | ]; 43 | return $this->flickr->request('flickr.photos.suggestions.getList', $params); 44 | } 45 | 46 | /** 47 | * Reject a suggestion for a photo. 48 | * 49 | * This method requires authentication. 50 | * 51 | * @link https://www.flickr.com/services/api/flickr.photos.suggestions.rejectSuggestion.html 52 | * @param string $suggestionId The unique ID of the suggestion to reject. 53 | * @return 54 | */ 55 | public function rejectSuggestion($suggestionId) 56 | { 57 | $params = [ 58 | 'suggestion_id' => $suggestionId 59 | ]; 60 | return $this->flickr->request('flickr.photos.suggestions.rejectSuggestion', $params); 61 | } 62 | 63 | /** 64 | * Remove a suggestion, made by the calling user, from a photo. 65 | * 66 | * This method requires authentication. 67 | * 68 | * @link https://www.flickr.com/services/api/flickr.photos.suggestions.removeSuggestion.html 69 | * @param string $suggestionId The unique ID for the location suggestion to 70 | * approve. 71 | * @return 72 | */ 73 | public function removeSuggestion($suggestionId) 74 | { 75 | $params = [ 76 | 'suggestion_id' => $suggestionId 77 | ]; 78 | return $this->flickr->request('flickr.photos.suggestions.removeSuggestion', $params); 79 | } 80 | 81 | /** 82 | * Suggest a geotagged location for a photo. 83 | * 84 | * This method requires authentication. 85 | * 86 | * @link https://www.flickr.com/services/api/flickr.photos.suggestions.suggestLocation.html 87 | * @param string $photoId The photo whose location you are suggesting. 88 | * @param string $lat The latitude whose valid range is -90 to 90. Anything more 89 | * than 6 decimal places will be truncated. 90 | * @param string $lon The longitude whose valid range is -180 to 180. Anything more 91 | * than 6 decimal places will be truncated. 92 | * @param string $accuracy Recorded accuracy level of the location information. 93 | * World level is 1, Country is ~3, Region ~6, City ~11, Street ~16. Current range 94 | * is 1-16. Defaults to 16 if not specified. 95 | * @param string $woeId The WOE ID of the location used to build the location 96 | * hierarchy for the photo. 97 | * @param string $placeId The Flickr Places ID of the location used to build the 98 | * location hierarchy for the photo. 99 | * @param string $note A short note or history to include with the suggestion. 100 | * @return 101 | */ 102 | public function suggestLocation( 103 | $photoId, 104 | $lat, 105 | $lon, 106 | $accuracy = null, 107 | $woeId = null, 108 | $placeId = null, 109 | $note = null 110 | ) { 111 | $params = [ 112 | 'photo_id' => $photoId, 113 | 'lat' => $lat, 114 | 'lon' => $lon, 115 | 'accuracy' => $accuracy, 116 | 'woe_id' => $woeId, 117 | 'place_id' => $placeId, 118 | 'note' => $note 119 | ]; 120 | return $this->flickr->request('flickr.photos.suggestions.suggestLocation', $params); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/PhotosPeopleApi.php: -------------------------------------------------------------------------------- 1 | $photoId, 29 | 'user_id' => $userId, 30 | 'person_x' => $personX, 31 | 'person_y' => $personY, 32 | 'person_w' => $personW, 33 | 'person_h' => $personH 34 | ]; 35 | return $this->flickr->request('flickr.photos.people.add', $params); 36 | } 37 | 38 | /** 39 | * Remove a person from a photo. 40 | * 41 | * This method requires authentication. 42 | * 43 | * @link https://www.flickr.com/services/api/flickr.photos.people.delete.html 44 | * @param string $photoId The id of the photo to remove a person from. 45 | * @param string $userId The NSID of the person to remove from the photo. 46 | * @return 47 | */ 48 | public function delete($photoId, $userId) 49 | { 50 | $params = [ 51 | 'photo_id' => $photoId, 52 | 'user_id' => $userId 53 | ]; 54 | return $this->flickr->request('flickr.photos.people.delete', $params); 55 | } 56 | 57 | /** 58 | * Remove the bounding box from a person in a photo 59 | * 60 | * This method requires authentication. 61 | * 62 | * @link https://www.flickr.com/services/api/flickr.photos.people.deleteCoords.html 63 | * @param string $photoId The id of the photo to edit a person in. 64 | * @param string $userId The NSID of the person whose bounding box you want to 65 | * remove. 66 | * @return 67 | */ 68 | public function deleteCoords($photoId, $userId) 69 | { 70 | $params = [ 71 | 'photo_id' => $photoId, 72 | 'user_id' => $userId 73 | ]; 74 | return $this->flickr->request('flickr.photos.people.deleteCoords', $params); 75 | } 76 | 77 | /** 78 | * Edit the bounding box of an existing person on a photo. 79 | * 80 | * This method requires authentication. 81 | * 82 | * @link https://www.flickr.com/services/api/flickr.photos.people.editCoords.html 83 | * @param string $photoId The id of the photo to edit a person in. 84 | * @param string $userId The NSID of the person to edit in a photo. 85 | * @param string $personX The left-most pixel co-ordinate of the box around the 86 | * person. 87 | * @param string $personY The top-most pixel co-ordinate of the box around the 88 | * person. 89 | * @param string $personW The width (in pixels) of the box around the person. 90 | * @param string $personH The height (in pixels) of the box around the person. 91 | * @return 92 | */ 93 | public function editCoords($photoId, $userId, $personX, $personY, $personW, $personH) 94 | { 95 | $params = [ 96 | 'photo_id' => $photoId, 97 | 'user_id' => $userId, 98 | 'person_x' => $personX, 99 | 'person_y' => $personY, 100 | 'person_w' => $personW, 101 | 'person_h' => $personH 102 | ]; 103 | return $this->flickr->request('flickr.photos.people.editCoords', $params); 104 | } 105 | 106 | /** 107 | * Get a list of people in a given photo. 108 | * 109 | * This method does not require authentication. 110 | * 111 | * @link https://www.flickr.com/services/api/flickr.photos.people.getList.html 112 | * @param string $photoId The id of the photo to get a list of people for. 113 | * @return 114 | */ 115 | public function getList($photoId) 116 | { 117 | $params = [ 118 | 'photo_id' => $photoId 119 | ]; 120 | return $this->flickr->request('flickr.photos.people.getList', $params); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/ContactsApi.php: -------------------------------------------------------------------------------- 1 |  
    friends
    Only 15 | * contacts who are friends (and not family)
    16 | *
    family
    Only contacts who are family (and not 17 | * friends)
    both
    Only contacts who are 18 | * both friends and family
    neither
    Only 19 | * contacts who are neither friends nor family
    20 | * @param string $page The page of results to return. If this argument is omitted, 21 | * it defaults to 1. 22 | * @param string $perPage Number of photos to return per page. If this argument is 23 | * omitted, it defaults to 1000. The maximum allowed value is 1000. 24 | * @param string $sort The order in which to sort the returned contacts. Defaults 25 | * to name. The possible values are: name and time. 26 | * @return 27 | */ 28 | public function getList($filter = null, $page = null, $perPage = null, $sort = null) 29 | { 30 | $params = [ 31 | 'filter' => $filter, 32 | 'page' => $page, 33 | 'per_page' => $perPage, 34 | 'sort' => $sort 35 | ]; 36 | return $this->flickr->request('flickr.contacts.getList', $params); 37 | } 38 | 39 | /** 40 | * Return a list of contacts for a user who have recently uploaded photos along 41 | * with the total count of photos uploaded.

    42 | 43 | This method is still 44 | * considered experimental. We don't plan for it to change or to go away but so 45 | * long as this notice is present you should write your code accordingly. 46 | * 47 | * This method requires authentication. 48 | * 49 | * @link https://www.flickr.com/services/api/flickr.contacts.getListRecentlyUploaded.html 50 | * @param string $dateLastupload Limits the resultset to contacts that have 51 | * uploaded photos since this date. The date should be in the form of a Unix 52 | * timestamp. The default offset is (1) hour and the maximum (24) hours. 53 | * @param string $filter Limit the result set to all contacts or only those who are 54 | * friends or family. Valid options are: Default value 56 | * is "all". 57 | * @return 58 | */ 59 | public function getListRecentlyUploaded($dateLastupload = null, $filter = null) 60 | { 61 | $params = [ 62 | 'date_lastupload' => $dateLastupload, 63 | 'filter' => $filter 64 | ]; 65 | return $this->flickr->request('flickr.contacts.getListRecentlyUploaded', $params); 66 | } 67 | 68 | /** 69 | * Get the contact list for a user. 70 | * 71 | * This method does not require authentication. 72 | * 73 | * @link https://www.flickr.com/services/api/flickr.contacts.getPublicList.html 74 | * @param string $userId The NSID of the user to fetch the contact list for. 75 | * @param string $page The page of results to return. If this argument is omitted, 76 | * it defaults to 1. 77 | * @param string $perPage Number of photos to return per page. If this argument is 78 | * omitted, it defaults to 1000. The maximum allowed value is 1000. 79 | * @return 80 | */ 81 | public function getPublicList($userId, $page = null, $perPage = null) 82 | { 83 | $params = [ 84 | 'user_id' => $userId, 85 | 'page' => $page, 86 | 'per_page' => $perPage 87 | ]; 88 | return $this->flickr->request('flickr.contacts.getPublicList', $params); 89 | } 90 | 91 | /** 92 | * Get suggestions for tagging people in photos based on the calling user's 93 | * contacts. 94 | * 95 | * This method requires authentication. 96 | * 97 | * @link https://www.flickr.com/services/api/flickr.contacts.getTaggingSuggestions.html 98 | * @param string $perPage Number of contacts to return per page. If this argument 99 | * is omitted, all contacts will be returned. 100 | * @param string $page The page of results to return. If this argument is omitted, 101 | * it defaults to 1. 102 | * @return 103 | */ 104 | public function getTaggingSuggestions($perPage = null, $page = null) 105 | { 106 | $params = [ 107 | 'per_page' => $perPage, 108 | 'page' => $page 109 | ]; 110 | return $this->flickr->request('flickr.contacts.getTaggingSuggestions', $params); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/GroupsDiscussRepliesApi.php: -------------------------------------------------------------------------------- 1 | $groupId, 24 | 'topic_id' => $topicId, 25 | 'message' => $message 26 | ]; 27 | return $this->flickr->request('flickr.groups.discuss.replies.add', $params); 28 | } 29 | 30 | /** 31 | * Delete a reply from a group topic. 32 | * 33 | * This method requires authentication. 34 | * 35 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.replies.delete.html 36 | * @param string $groupId Pass in the group id to where the topic belongs. Can be 37 | * NSID or group alias. Making this parameter optional for legacy reasons, but it 38 | * is highly recommended to pass this in to get faster performance. 39 | * @param string $topicId The ID of the topic the post is in. 40 | * @param string $replyId The ID of the reply to delete. 41 | * @return 42 | */ 43 | public function delete($groupId, $topicId, $replyId) 44 | { 45 | $params = [ 46 | 'group_id' => $groupId, 47 | 'topic_id' => $topicId, 48 | 'reply_id' => $replyId 49 | ]; 50 | return $this->flickr->request('flickr.groups.discuss.replies.delete', $params); 51 | } 52 | 53 | /** 54 | * Edit a topic reply. 55 | * 56 | * This method requires authentication. 57 | * 58 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.replies.edit.html 59 | * @param string $groupId Pass in the group id to where the topic belongs. Can be 60 | * NSID or group alias. Making this parameter optional for legacy reasons, but it 61 | * is highly recommended to pass this in to get faster performance. 62 | * @param string $topicId The ID of the topic the post is in. 63 | * @param string $replyId The ID of the reply post to edit. 64 | * @param string $message The message to edit the post with. 65 | * @return 66 | */ 67 | public function edit($groupId, $topicId, $replyId, $message) 68 | { 69 | $params = [ 70 | 'group_id' => $groupId, 71 | 'topic_id' => $topicId, 72 | 'reply_id' => $replyId, 73 | 'message' => $message 74 | ]; 75 | return $this->flickr->request('flickr.groups.discuss.replies.edit', $params); 76 | } 77 | 78 | /** 79 | * Get information on a group topic reply. 80 | * 81 | * This method does not require authentication. 82 | * 83 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.replies.getInfo.html 84 | * @param string $groupId Pass in the group id to where the topic belongs. Can be 85 | * NSID or group alias. Making this parameter optional for legacy reasons, but it 86 | * is highly recommended to pass this in to get faster performance. 87 | * @param string $topicId The ID of the topic the post is in. 88 | * @param string $replyId The ID of the reply to fetch. 89 | * @return 90 | */ 91 | public function getInfo($groupId, $topicId, $replyId) 92 | { 93 | $params = [ 94 | 'group_id' => $groupId, 95 | 'topic_id' => $topicId, 96 | 'reply_id' => $replyId 97 | ]; 98 | return $this->flickr->request('flickr.groups.discuss.replies.getInfo', $params); 99 | } 100 | 101 | /** 102 | * Get a list of replies from a group discussion topic. 103 | * 104 | * This method does not require authentication. 105 | * 106 | * @link https://www.flickr.com/services/api/flickr.groups.discuss.replies.getList.html 107 | * @param string $groupId Pass in the group id to where the topic belongs. Can be 108 | * NSID or group alias. Making this parameter optional for legacy reasons, but it 109 | * is highly recommended to pass this in to get faster performance. 110 | * @param string $topicId The ID of the topic to fetch replies for. 111 | * @param string $perPage Number of photos to return per page. If this argument is 112 | * omitted, it defaults to 100. The maximum allowed value is 500. 113 | * @param string $page The page of results to return. If this argument is omitted, 114 | * it defaults to 1. 115 | * @return 116 | */ 117 | public function getList($groupId, $topicId, $perPage, $page = null) 118 | { 119 | $params = [ 120 | 'group_id' => $groupId, 121 | 'topic_id' => $topicId, 122 | 'per_page' => $perPage, 123 | 'page' => $page 124 | ]; 125 | return $this->flickr->request('flickr.groups.discuss.replies.getList', $params); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/PhotosCommentsApi.php: -------------------------------------------------------------------------------- 1 | $photoId, 21 | 'comment_text' => $commentText 22 | ]; 23 | return $this->flickr->request('flickr.photos.comments.addComment', $params); 24 | } 25 | 26 | /** 27 | * Delete a comment as the currently authenticated user. 28 | * 29 | * This method requires authentication. 30 | * 31 | * @link https://www.flickr.com/services/api/flickr.photos.comments.deleteComment.html 32 | * @param string $commentId The id of the comment to edit. 33 | * @return 34 | */ 35 | public function deleteComment($commentId) 36 | { 37 | $params = [ 38 | 'comment_id' => $commentId 39 | ]; 40 | return $this->flickr->request('flickr.photos.comments.deleteComment', $params); 41 | } 42 | 43 | /** 44 | * Edit the text of a comment as the currently authenticated user. 45 | * 46 | * This method requires authentication. 47 | * 48 | * @link https://www.flickr.com/services/api/flickr.photos.comments.editComment.html 49 | * @param string $commentId The id of the comment to edit. 50 | * @param string $commentText Update the comment to this text. 51 | * @return 52 | */ 53 | public function editComment($commentId, $commentText) 54 | { 55 | $params = [ 56 | 'comment_id' => $commentId, 57 | 'comment_text' => $commentText 58 | ]; 59 | return $this->flickr->request('flickr.photos.comments.editComment', $params); 60 | } 61 | 62 | /** 63 | * Returns the comments for a photo 64 | * 65 | * This method does not require authentication. 66 | * 67 | * @link https://www.flickr.com/services/api/flickr.photos.comments.getList.html 68 | * @param string $photoId The id of the photo to fetch comments for. 69 | * @param string $minCommentDate Minimum date that a a comment was added. The date 70 | * should be in the form of a unix timestamp. 71 | * @param string $maxCommentDate Maximum date that a comment was added. The date 72 | * should be in the form of a unix timestamp. 73 | * @return 74 | */ 75 | public function getList($photoId, $minCommentDate = null, $maxCommentDate = null) 76 | { 77 | $params = [ 78 | 'photo_id' => $photoId, 79 | 'min_comment_date' => $minCommentDate, 80 | 'max_comment_date' => $maxCommentDate 81 | ]; 82 | return $this->flickr->request('flickr.photos.comments.getList', $params); 83 | } 84 | 85 | /** 86 | * Return the list of photos belonging to your contacts that have been commented on 87 | * recently. 88 | * 89 | * This method requires authentication. 90 | * 91 | * @link https://www.flickr.com/services/api/flickr.photos.comments.getRecentForContacts.html 92 | * @param string $dateLastcomment Limits the resultset to photos that have been 93 | * commented on since this date. The date should be in the form of a Unix 94 | * timestamp.

    The default, and maximum, offset is (1) hour. 95 | * @param string $contactsFilter A comma-separated list of contact NSIDs to limit 96 | * the scope of the query to. 97 | * @param string $extras A comma-delimited list of extra information to fetch for 98 | * each returned record. Currently supported fields are: description, 99 | * license, date_upload, date_taken, 100 | * owner_name, icon_server, original_format, 101 | * last_update, geo, tags, 102 | * machine_tags, o_dims, views, 103 | * media, path_alias, url_sq, 104 | * url_t, url_s, url_q, url_m, 105 | * url_n, url_z, url_c, url_l, 106 | * url_o 107 | * @param string $perPage Number of photos to return per page. If this argument is 108 | * omitted, it defaults to 100. The maximum allowed value is 500. 109 | * @param string $page The page of results to return. If this argument is omitted, 110 | * it defaults to 1. 111 | * @return 112 | */ 113 | public function getRecentForContacts( 114 | $dateLastcomment = null, 115 | $contactsFilter = null, 116 | $extras = null, 117 | $perPage = null, 118 | $page = null 119 | ) { 120 | $params = [ 121 | 'date_lastcomment' => $dateLastcomment, 122 | 'contacts_filter' => $contactsFilter, 123 | 'extras' => $extras, 124 | 'per_page' => $perPage, 125 | 'page' => $page 126 | ]; 127 | return $this->flickr->request('flickr.photos.comments.getRecentForContacts', $params); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/GroupsPoolsApi.php: -------------------------------------------------------------------------------- 1 | $photoId, 23 | 'group_id' => $groupId 24 | ]; 25 | return $this->flickr->request('flickr.groups.pools.add', $params); 26 | } 27 | 28 | /** 29 | * Returns next and previous photos for a photo in a group pool. 30 | * 31 | * This method does not require authentication. 32 | * 33 | * @link https://www.flickr.com/services/api/flickr.groups.pools.getContext.html 34 | * @param string $photoId The id of the photo to fetch the context for. 35 | * @param string $groupId The nsid of the group who's pool to fetch the photo's 36 | * context for. 37 | * @return 38 | */ 39 | public function getContext($photoId, $groupId) 40 | { 41 | $params = [ 42 | 'photo_id' => $photoId, 43 | 'group_id' => $groupId 44 | ]; 45 | return $this->flickr->request('flickr.groups.pools.getContext', $params); 46 | } 47 | 48 | /** 49 | * Returns a list of groups to which you can add photos. 50 | * 51 | * This method requires authentication. 52 | * 53 | * @link https://www.flickr.com/services/api/flickr.groups.pools.getGroups.html 54 | * @param string $page The page of results to return. If this argument is omitted, 55 | * it defaults to 1. 56 | * @param string $perPage Number of groups to return per page. If this argument is 57 | * omitted, it defaults to 400. The maximum allowed value is 400. 58 | * @return 59 | */ 60 | public function getGroups($page = null, $perPage = null) 61 | { 62 | $params = [ 63 | 'page' => $page, 64 | 'per_page' => $perPage 65 | ]; 66 | return $this->flickr->request('flickr.groups.pools.getGroups', $params); 67 | } 68 | 69 | /** 70 | * Returns a list of pool photos for a given group, based on the permissions of the 71 | * group and the user logged in (if any). 72 | * 73 | * This method does not require authentication. 74 | * 75 | * @link https://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html 76 | * @param string $groupId The id of the group who's pool you which to get the photo 77 | * list for. 78 | * @param string $tags A tag to filter the pool with. At the moment only one tag at 79 | * a time is supported. 80 | * @param string $userId The nsid of a user. Specifiying this parameter will 81 | * retrieve for you only those photos that the user has contributed to the group 82 | * pool. 83 | * @param string $extras A comma-delimited list of extra information to fetch for 84 | * each returned record. Currently supported fields are: description, 85 | * license, date_upload, date_taken, 86 | * owner_name, icon_server, original_format, 87 | * last_update, geo, tags, 88 | * machine_tags, o_dims, views, 89 | * media, path_alias, url_sq, 90 | * url_t, url_s, url_q, url_m, 91 | * url_n, url_z, url_c, url_l, 92 | * url_o 93 | * @param string $perPage Number of photos to return per page. If this argument is 94 | * omitted, it defaults to 100. The maximum allowed value is 500. 95 | * @param string $page The page of results to return. If this argument is omitted, 96 | * it defaults to 1. 97 | * @return 98 | */ 99 | public function getPhotos($groupId, $tags = null, $userId = null, $extras = null, $perPage = null, $page = null) 100 | { 101 | $params = [ 102 | 'group_id' => $groupId, 103 | 'tags' => $tags, 104 | 'user_id' => $userId, 105 | 'extras' => $extras, 106 | 'per_page' => $perPage, 107 | 'page' => $page 108 | ]; 109 | return $this->flickr->request('flickr.groups.pools.getPhotos', $params); 110 | } 111 | 112 | /** 113 | * Remove a photo from a group pool. 114 | * 115 | * This method requires authentication. 116 | * 117 | * @link https://www.flickr.com/services/api/flickr.groups.pools.remove.html 118 | * @param string $photoId The id of the photo to remove from the group pool. The 119 | * photo must either be owned by the calling user of the calling user must be an 120 | * administrator of the group. 121 | * @param string $groupId The NSID of the group who's pool the photo is to removed 122 | * from. 123 | * @return 124 | */ 125 | public function remove($photoId, $groupId) 126 | { 127 | $params = [ 128 | 'photo_id' => $photoId, 129 | 'group_id' => $groupId 130 | ]; 131 | return $this->flickr->request('flickr.groups.pools.remove', $params); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/MachinetagsApi.php: -------------------------------------------------------------------------------- 1 | $predicate, 26 | 'per_page' => $perPage, 27 | 'page' => $page 28 | ]; 29 | return $this->flickr->request('flickr.machinetags.getNamespaces', $params); 30 | } 31 | 32 | /** 33 | * Return a list of unique namespace and predicate pairs, optionally limited by 34 | * predicate or namespace, in alphabetical order. 35 | * 36 | * This method does not require authentication. 37 | * 38 | * @link https://www.flickr.com/services/api/flickr.machinetags.getPairs.html 39 | * @param string $namespace Limit the list of pairs returned to those that have the 40 | * following namespace. 41 | * @param string $predicate Limit the list of pairs returned to those that have the 42 | * following predicate. 43 | * @param string $perPage Number of photos to return per page. If this argument is 44 | * omitted, it defaults to 100. The maximum allowed value is 500. 45 | * @param string $page The page of results to return. If this argument is omitted, 46 | * it defaults to 1. 47 | * @return 48 | */ 49 | public function getPairs($namespace = null, $predicate = null, $perPage = null, $page = null) 50 | { 51 | $params = [ 52 | 'namespace' => $namespace, 53 | 'predicate' => $predicate, 54 | 'per_page' => $perPage, 55 | 'page' => $page 56 | ]; 57 | return $this->flickr->request('flickr.machinetags.getPairs', $params); 58 | } 59 | 60 | /** 61 | * Return a list of unique predicates, optionally limited by a given namespace. 62 | * 63 | * This method does not require authentication. 64 | * 65 | * @link https://www.flickr.com/services/api/flickr.machinetags.getPredicates.html 66 | * @param string $namespace Limit the list of predicates returned to those that 67 | * have the following namespace. 68 | * @param string $perPage Number of photos to return per page. If this argument is 69 | * omitted, it defaults to 100. The maximum allowed value is 500. 70 | * @param string $page The page of results to return. If this argument is omitted, 71 | * it defaults to 1. 72 | * @return 73 | */ 74 | public function getPredicates($namespace = null, $perPage = null, $page = null) 75 | { 76 | $params = [ 77 | 'namespace' => $namespace, 78 | 'per_page' => $perPage, 79 | 'page' => $page 80 | ]; 81 | return $this->flickr->request('flickr.machinetags.getPredicates', $params); 82 | } 83 | 84 | /** 85 | * Fetch recently used (or created) machine tags values. 86 | * 87 | * This method does not require authentication. 88 | * 89 | * @link https://www.flickr.com/services/api/flickr.machinetags.getRecentValues.html 90 | * @param string $namespace A namespace that all values should be restricted to. 91 | * @param string $predicate A predicate that all values should be restricted to. 92 | * @param string $addedSince Only return machine tags values that have been added 93 | * since this timestamp, in epoch seconds. 94 | * @return 95 | */ 96 | public function getRecentValues($namespace = null, $predicate = null, $addedSince = null) 97 | { 98 | $params = [ 99 | 'namespace' => $namespace, 100 | 'predicate' => $predicate, 101 | 'added_since' => $addedSince 102 | ]; 103 | return $this->flickr->request('flickr.machinetags.getRecentValues', $params); 104 | } 105 | 106 | /** 107 | * Return a list of unique values for a namespace and predicate. 108 | * 109 | * This method does not require authentication. 110 | * 111 | * @link https://www.flickr.com/services/api/flickr.machinetags.getValues.html 112 | * @param string $namespace The namespace that all values should be restricted to. 113 | * @param string $predicate The predicate that all values should be restricted to. 114 | * @param string $perPage Number of photos to return per page. If this argument is 115 | * omitted, it defaults to 100. The maximum allowed value is 500. 116 | * @param string $page The page of results to return. If this argument is omitted, 117 | * it defaults to 1. 118 | * @return 119 | */ 120 | public function getValues($namespace, $predicate, $perPage = null, $page = null) 121 | { 122 | $params = [ 123 | 'namespace' => $namespace, 124 | 'predicate' => $predicate, 125 | 'per_page' => $perPage, 126 | 'page' => $page 127 | ]; 128 | return $this->flickr->request('flickr.machinetags.getValues', $params); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/GroupsApi.php: -------------------------------------------------------------------------------- 1 | $catId 22 | ]; 23 | return $this->flickr->request('flickr.groups.browse', $params); 24 | } 25 | 26 | /** 27 | * Get information about a group. 28 | * 29 | * This method does not require authentication. 30 | * 31 | * @link https://www.flickr.com/services/api/flickr.groups.getInfo.html 32 | * @param string $groupId The NSID of the group to fetch information for. 33 | * @param string $groupPathAlias The path alias of the group. One of this or the 34 | * group_id param is required 35 | * @param string $lang The language of the group name and description to fetch. If 36 | * the language is not found, the primary language of the group will be returned. 37 | * Valid values are the same as in feeds. 38 | * @return 39 | */ 40 | public function getInfo($groupId, $groupPathAlias = null, $lang = null) 41 | { 42 | $params = [ 43 | 'group_id' => $groupId, 44 | 'group_path_alias' => $groupPathAlias, 45 | 'lang' => $lang 46 | ]; 47 | return $this->flickr->request('flickr.groups.getInfo', $params); 48 | } 49 | 50 | /** 51 | * Join a public group as a member. 52 | * 53 | * This method requires authentication. 54 | * 55 | * @link https://www.flickr.com/services/api/flickr.groups.join.html 56 | * @param string $groupId The NSID of the Group in question 57 | * @param string $acceptRules If the group has rules, they must be displayed to the 58 | * user prior to joining. Passing a true value for this argument specifies that the 59 | * application has displayed the group rules to the user, and that the user has 60 | * agreed to them. (See flickr.groups.getInfo). 61 | * @return 62 | */ 63 | public function join($groupId, $acceptRules = null) 64 | { 65 | $params = [ 66 | 'group_id' => $groupId, 67 | 'accept_rules' => $acceptRules 68 | ]; 69 | return $this->flickr->request('flickr.groups.join', $params); 70 | } 71 | 72 | /** 73 | * Request to join a group that is invitation-only. 74 | * 75 | * This method requires authentication. 76 | * 77 | * @link https://www.flickr.com/services/api/flickr.groups.joinRequest.html 78 | * @param string $groupId The NSID of the group to request joining. 79 | * @param string $message Message to the administrators. 80 | * @param string $acceptRules If the group has rules, they must be displayed to the 81 | * user prior to joining. Passing a true value for this argument specifies that the 82 | * application has displayed the group rules to the user, and that the user has 83 | * agreed to them. (See flickr.groups.getInfo). 84 | * @return 85 | */ 86 | public function joinRequest($groupId, $message, $acceptRules) 87 | { 88 | $params = [ 89 | 'group_id' => $groupId, 90 | 'message' => $message, 91 | 'accept_rules' => $acceptRules 92 | ]; 93 | return $this->flickr->request('flickr.groups.joinRequest', $params); 94 | } 95 | 96 | /** 97 | * Leave a group. 98 | 99 |

    If the user is the only administrator left, and 100 | * there are other members, the oldest member will be promoted to 101 | * administrator. 102 | 103 |

    If the user is the last person in the group, the 104 | * group will be deleted. 105 | * 106 | * This method requires authentication. 107 | * 108 | * @link https://www.flickr.com/services/api/flickr.groups.leave.html 109 | * @param string $groupId The NSID of the Group to leave 110 | * @param string $deletePhotos Delete all photos by this user from the group 111 | * @return 112 | */ 113 | public function leave($groupId, $deletePhotos = null) 114 | { 115 | $params = [ 116 | 'group_id' => $groupId, 117 | 'delete_photos' => $deletePhotos 118 | ]; 119 | return $this->flickr->request('flickr.groups.leave', $params); 120 | } 121 | 122 | /** 123 | * Search for groups. 18+ groups will only be returned for authenticated calls 124 | * where the authenticated user is over 18. 125 | * 126 | * This method does not require authentication. 127 | * 128 | * @link https://www.flickr.com/services/api/flickr.groups.search.html 129 | * @param string $text The text to search for. 130 | * @param string $perPage Number of groups to return per page. If this argument is 131 | * ommited, it defaults to 100. The maximum allowed value is 500. 132 | * @param string $page The page of results to return. If this argument is ommited, 133 | * it defaults to 1. 134 | * @return 135 | */ 136 | public function search($text, $perPage = null, $page = null) 137 | { 138 | $params = [ 139 | 'text' => $text, 140 | 'per_page' => $perPage, 141 | 'page' => $page 142 | ]; 143 | return $this->flickr->request('flickr.groups.search', $params); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /tests/ApiMethodGroup/PhotosApiTest.php: -------------------------------------------------------------------------------- 1 | testPhotoId) { 18 | return $this->testPhotoId; 19 | } 20 | $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; 21 | $photo = $flickr->uploader()->upload($testFilename); 22 | $this->testPhotoId = $photo['photoid']; 23 | return $this->testPhotoId; 24 | } 25 | 26 | public function testAddTags() 27 | { 28 | $flickr = $this->getFlickr(true); 29 | $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; 30 | $photo = $flickr->uploader()->upload($testFilename); 31 | 32 | // Add a string of tags. 33 | $tagString = 'Tag Iñtërnâtiônàlizætiøn "Third Tag"'; 34 | $tagsAdded1 = $flickr->photos()->addTags($photo['photoid'], $tagString); 35 | static::assertTrue($tagsAdded1); 36 | $photoInfo = $flickr->photos()->getInfo($photo['photoid']); 37 | static::assertCount(3, $photoInfo['tags']['tag']); 38 | $tags1 = []; 39 | foreach ($photoInfo['tags']['tag'] as $tagInfo) { 40 | $tags1[] = $tagInfo['raw']; 41 | } 42 | static::assertEquals(['Tag', 'Iñtërnâtiônàlizætiøn', 'Third Tag'], $tags1); 43 | 44 | // Add an array of tags. 45 | $tagsAdded2 = $flickr->photos()->addTags($photo['photoid'], ['Four', '"With quotes"']); 46 | static::assertTrue($tagsAdded2); 47 | $photoInfo2 = $flickr->photos()->getInfo($photo['photoid']); 48 | static::assertCount(5, $photoInfo2['tags']['tag']); 49 | $tags2 = []; 50 | foreach ($photoInfo2['tags']['tag'] as $tagInfo) { 51 | $tags2[] = $tagInfo['raw']; 52 | } 53 | static::assertEquals( 54 | ['Tag', 'Iñtërnâtiônàlizætiøn', 'Third Tag', 'Four', 'With quotes'], 55 | $tags2 56 | ); 57 | 58 | // Clean up. 59 | $flickr->photos()->delete($photo['photoid']); 60 | } 61 | 62 | public function testSetTags() 63 | { 64 | $flickr = $this->getFlickr(true); 65 | $testPhotoId = $this->getTestPhotoId($flickr); 66 | 67 | $photoInfo = $flickr->photos()->getInfo($testPhotoId); 68 | static::assertCount(0, $photoInfo['tags']['tag']); 69 | 70 | $tagString = 'Tag Iñtërnâtiônàlizætiøn "Third Tag"'; 71 | $tagsResult = $flickr->photos()->setTags($testPhotoId, $tagString); 72 | static::assertTrue($tagsResult); 73 | 74 | $photoInfo = $flickr->photos()->getInfo($testPhotoId); 75 | static::assertCount(3, $photoInfo['tags']['tag']); 76 | 77 | // Clean up. 78 | $flickr->photos()->delete($testPhotoId); 79 | } 80 | 81 | public function testSearch() 82 | { 83 | $flickr = $this->getFlickr(true); 84 | $testTitle = uniqid('PhpFlickr search test '); 85 | $searchParams = [ 86 | 'user_id' => 'me', 87 | 'text' => $testTitle, 88 | ]; 89 | 90 | // Make sure there are no search results to start with. 91 | $search = $flickr->photos()->search($searchParams); 92 | static::assertCount(0, $search['photo']); 93 | 94 | // Upload a test photo. 95 | $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; 96 | $photo = $flickr->uploader()->upload($testFilename, $testTitle, null, null, true, null, null, null, 1); 97 | 98 | // Look for search results, looping because it's a new file and can take time to be indexed. 99 | for ($i = 0; $i < 15; $i++) { 100 | sleep(1); 101 | $search = $flickr->photos()->search($searchParams); 102 | if (count($search['photo']) > 0) { 103 | break; 104 | } 105 | } 106 | static::assertGreaterThanOrEqual(1, count($search['photo'])); 107 | 108 | // Clean up. 109 | $flickr->photos()->delete($photo['photoid']); 110 | } 111 | 112 | public function testSetMeta() 113 | { 114 | $flickr = $this->getFlickr(true); 115 | $testPhotoId = $this->getTestPhotoId($flickr); 116 | 117 | // Set title and description on a known photo, and check them in a 2nd request. 118 | $metaResponse = $flickr->photos()->setMeta($testPhotoId, 'New title', 'New description'); 119 | static::assertTrue($metaResponse); 120 | $info = $flickr->photos()->getInfo($testPhotoId); 121 | static::assertEquals('New title', $info['title']); 122 | static::assertEquals('New description', $info['description']); 123 | 124 | // Test for an error with an invalid photo ID. 125 | static::expectExceptionMessage('Photo "1" not found (invalid ID)'); 126 | $flickr->photos()->setMeta(1, 'Lorem'); 127 | 128 | // Clean up. 129 | $flickr->photos()->delete($testPhotoId); 130 | } 131 | 132 | public function testSetDates() 133 | { 134 | $flickr = $this->getFlickr(true); 135 | $testPhotoId = $this->getTestPhotoId($flickr); 136 | 137 | $datesResponse = $flickr->photos()->setDates( 138 | $testPhotoId, 139 | new DateTime('2019-02-10 13:24'), 140 | Util::DATE_GRANULARITY_YEAR 141 | ); 142 | static::assertTrue($datesResponse); 143 | $info = $flickr->photos()->getInfo($testPhotoId); 144 | static::assertEquals('2019-01-01 00:00:00', $info['dates']['taken']); 145 | static::assertEquals(6, $info['dates']['takengranularity']); 146 | 147 | // Clean up. 148 | $flickr->photos()->delete($testPhotoId); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/UrlsApi.php: -------------------------------------------------------------------------------- 1 | "_s", 21 | "square_75" => "_s", 22 | "square_150" => "_q", 23 | "thumbnail" => "_t", 24 | "small" => "_m", 25 | "small_240" => "_m", 26 | "small_320" => "_n", 27 | "medium" => "", 28 | "medium_500" => "", 29 | "medium_640" => "_z", 30 | "medium_800" => "_c", 31 | "large" => "_b", 32 | "large_1024" => "_b", 33 | "large_1600" => "_h", 34 | "large_2048" => "_k", 35 | "original" => "_o", 36 | ]; 37 | 38 | // Default to medium size. 39 | $sizeSuffix = ''; 40 | 41 | // Backwards compatibility. 42 | if (isset($sizeSuffixes[$size])) { 43 | $sizeSuffix = $sizeSuffixes[$size]; 44 | } 45 | 46 | // Create non-medium suffix. 47 | if (in_array('_' . $size, $sizeSuffixes)) { 48 | $sizeSuffix = '_' . $size; 49 | } 50 | 51 | $url = sprintf( 52 | 'https://farm%s.staticflickr.com/%s/%s', 53 | $photoInfo['farm'], 54 | $photoInfo['server'], 55 | $photoInfo['id'] 56 | ); 57 | if ($size === PhotosApi::SIZE_ORIGINAL) { 58 | $url .= '_' . $photoInfo['originalsecret'] . '_o.' . $photoInfo['originalformat']; 59 | } else { 60 | $url .= '_' . $photoInfo['secret'] . $sizeSuffix . '.jpg'; 61 | } 62 | return $url; 63 | } 64 | 65 | /** 66 | * Get the short URL for a single photo (using the 'flic.kr' domain name). 67 | * @param int $photoId 68 | * @return string 69 | */ 70 | public function getShortUrl($photoId) 71 | { 72 | return 'https://flic.kr/p/' . Util::base58encode($photoId); 73 | } 74 | 75 | /** 76 | * Returns the URL to a group's page. 77 | * 78 | * This method does not require authentication. 79 | * 80 | * @link https://www.flickr.com/services/api/flickr.urls.getGroup.html 81 | * @param string $groupId The NSID of the group to fetch the URL for. 82 | * @return string|bool 83 | */ 84 | public function getGroup($groupId) 85 | { 86 | $response = $this->flickr->request('flickr.urls.getGroup', ['group_id' => $groupId]); 87 | return isset($response['group']['url']) ? $response['group']['url'] : false; 88 | } 89 | 90 | /** 91 | * Returns the URL to a user's photos. 92 | * 93 | * This method does not require authentication. 94 | * 95 | * @link https://www.flickr.com/services/api/flickr.urls.getUserPhotos.html 96 | * @param string $userId The NSID of the user to fetch the URL for. If omitted, the calling user is assumed. 97 | * @return string|bool 98 | */ 99 | public function getUserPhotos($userId = null) 100 | { 101 | $response = $this->flickr->request('flickr.urls.getUserPhotos', ['user_id' => $userId]); 102 | return isset($response['user']['url']) ? $response['user']['url'] : false; 103 | } 104 | 105 | /** 106 | * Returns the URL to a user's profile. 107 | * 108 | * This method does not require authentication. 109 | * 110 | * @link https://www.flickr.com/services/api/flickr.urls.getUserProfile.html 111 | * @param string $userId The NSID of the user to fetch the URL for. If omitted, the calling user is assumed. 112 | * @return string|bool 113 | */ 114 | public function getUserProfile($userId = null) 115 | { 116 | $response = $this->flickr->request('flickr.urls.getUserProfile', ['user_id' => $userId]); 117 | return isset($response['user']['url']) ? $response['user']['url'] : false; 118 | } 119 | 120 | /** 121 | * Returns gallery info given a gallery's URL. 122 | * This method does not require authentication. 123 | * @link https://www.flickr.com/services/api/flickr.urls.lookupGallery.html 124 | * @param string $url The gallery's URL. 125 | * @return string|bool 126 | */ 127 | public function lookupGallery($url) 128 | { 129 | return $this->flickr->request('flickr.urls.lookupGallery', ['url' => $url]); 130 | } 131 | 132 | /** 133 | * Returns a group NSID, given the URL to a group's page or photo pool. 134 | * 135 | * This method does not require authentication. 136 | * 137 | * @link https://www.flickr.com/services/api/flickr.urls.lookupGroup.html 138 | * @param string $url The URL to the group's page or photo pool. 139 | * @return string|bool 140 | */ 141 | public function lookupGroup($url) 142 | { 143 | $response = $this->flickr->request('flickr.urls.lookupGroup', ['url' => $url]); 144 | return isset($response['group']) ? $response['group'] : false; 145 | } 146 | 147 | /** 148 | * Returns a user NSID, given the url to a user's photos or profile. 149 | * 150 | * This method does not require authentication. 151 | * 152 | * @link https://www.flickr.com/services/api/flickr.urls.lookupUser.html 153 | * @param string $url The URL to the user's profile or photos page. 154 | * @return string|bool 155 | */ 156 | public function lookupUser($url) 157 | { 158 | $response = $this->flickr->request('flickr.urls.lookupUser', ['url' => $url]); 159 | return isset($response['user']) ? $response['user'] : false; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/TagsApi.php: -------------------------------------------------------------------------------- 1 | $tag, 22 | 'cluster_id' => $clusterId 23 | ]; 24 | return $this->flickr->request('flickr.tags.getClusterPhotos', $params); 25 | } 26 | 27 | /** 28 | * Gives you a list of tag clusters for the given tag. 29 | * 30 | * This method does not require authentication. 31 | * 32 | * @link https://www.flickr.com/services/api/flickr.tags.getClusters.html 33 | * @param string $tag The tag to fetch clusters for. 34 | * @return 35 | */ 36 | public function getClusters($tag) 37 | { 38 | $params = [ 39 | 'tag' => $tag 40 | ]; 41 | return $this->flickr->request('flickr.tags.getClusters', $params); 42 | } 43 | 44 | /** 45 | * Returns a list of hot tags for the given period. 46 | * 47 | * This method does not require authentication. 48 | * 49 | * @link https://www.flickr.com/services/api/flickr.tags.getHotList.html 50 | * @param string $period The period for which to fetch hot tags. Valid values are 51 | * day and week (defaults to day). 52 | * @param string $count The number of tags to return. Defaults to 20. Maximum 53 | * allowed value is 200. 54 | * @return 55 | */ 56 | public function getHotList($period = null, $count = null) 57 | { 58 | $params = [ 59 | 'period' => $period, 60 | 'count' => $count 61 | ]; 62 | return $this->flickr->request('flickr.tags.getHotList', $params); 63 | } 64 | 65 | /** 66 | * Get the tag list for a given photo. 67 | * 68 | * This method does not require authentication. 69 | * 70 | * @link https://www.flickr.com/services/api/flickr.tags.getListPhoto.html 71 | * @param string $photoId The id of the photo to return tags for. 72 | * @return 73 | */ 74 | public function getListPhoto($photoId) 75 | { 76 | $params = [ 77 | 'photo_id' => $photoId 78 | ]; 79 | return $this->flickr->request('flickr.tags.getListPhoto', $params); 80 | } 81 | 82 | /** 83 | * Get the tag list for a given user (or the currently logged in user). 84 | * 85 | * This method does not require authentication. 86 | * 87 | * @link https://www.flickr.com/services/api/flickr.tags.getListUser.html 88 | * @param string $userId The NSID of the user to fetch the tag list for. If this 89 | * argument is not specified, the currently logged in user (if any) is assumed. 90 | * @return 91 | */ 92 | public function getListUser($userId = null) 93 | { 94 | $params = [ 95 | 'user_id' => $userId 96 | ]; 97 | return $this->flickr->request('flickr.tags.getListUser', $params); 98 | } 99 | 100 | /** 101 | * Get the popular tags for a given user (or the currently logged in user). 102 | * 103 | * This method does not require authentication. 104 | * 105 | * @link https://www.flickr.com/services/api/flickr.tags.getListUserPopular.html 106 | * @param string $userId The NSID of the user to fetch the tag list for. If this 107 | * argument is not specified, the currently logged in user (if any) is assumed. 108 | * @param string $count Number of popular tags to return. defaults to 10 when this 109 | * argument is not present. 110 | * @return 111 | */ 112 | public function getListUserPopular($userId = null, $count = null) 113 | { 114 | $params = [ 115 | 'user_id' => $userId, 116 | 'count' => $count 117 | ]; 118 | return $this->flickr->request('flickr.tags.getListUserPopular', $params); 119 | } 120 | 121 | /** 122 | * Get the raw versions of a given tag (or all tags) for the currently logged-in 123 | * user. 124 | * 125 | * This method does not require authentication. 126 | * 127 | * @link https://www.flickr.com/services/api/flickr.tags.getListUserRaw.html 128 | * @param string $tag The tag you want to retrieve all raw versions for. 129 | * @return 130 | */ 131 | public function getListUserRaw($tag = null) 132 | { 133 | $params = [ 134 | 'tag' => $tag 135 | ]; 136 | return $this->flickr->request('flickr.tags.getListUserRaw', $params); 137 | } 138 | 139 | /** 140 | * Returns a list of most frequently used tags for a user. 141 | * 142 | * This method requires authentication. 143 | * 144 | * @link https://www.flickr.com/services/api/flickr.tags.getMostFrequentlyUsed.html 145 | * 146 | * @return 147 | */ 148 | public function getMostFrequentlyUsed() 149 | { 150 | return $this->flickr->request('flickr.tags.getMostFrequentlyUsed'); 151 | } 152 | 153 | /** 154 | * Returns a list of tags 'related' to the given tag, based on clustered usage 155 | * analysis. 156 | * 157 | * This method does not require authentication. 158 | * 159 | * @link https://www.flickr.com/services/api/flickr.tags.getRelated.html 160 | * @param string $tag The tag to fetch related tags for. 161 | * @return 162 | */ 163 | public function getRelated($tag) 164 | { 165 | $params = [ 166 | 'tag' => $tag 167 | ]; 168 | return $this->flickr->request('flickr.tags.getRelated', $params); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Uploader.php: -------------------------------------------------------------------------------- 1 | flickr = $flickr; 28 | } 29 | 30 | /** 31 | * Upload a photo. 32 | * @link https://www.flickr.com/services/api/upload.api.html 33 | * @param string $photoFilename Full filesystem path to the photo to upload. 34 | * @param string|null $title The title of the photo. 35 | * @param string|null $description A description of the photo. May contain some limited HTML. 36 | * @param string|null $tags A space-seperated list of tags to apply to the photo. 37 | * @param bool|null $isPublic Specifies who can view the photo. If omitted permissions will 38 | * be set to user's default. 39 | * @param bool|null $isFriend Specifies who can view the photo. If omitted permissions will 40 | * be set to user's default. 41 | * @param bool|null $isFamily Specifies who can view the photo. If omitted permissions will 42 | * be set to user's default. 43 | * @param int|null $contentType Set to 1 for Photo, 2 for Screenshot, or 3 for Other. If 44 | * omitted , will be set to user's default. 45 | * @param int|null $hidden Set to 1 to keep the photo in global search results, 2 to hide from 46 | * public searches. If omitted, will be set based to user's default. 47 | * @param bool $async Whether to upload the file asynchronously (in which case a 'ticketid' 48 | * will be returned). 49 | * @return string[] 50 | */ 51 | public function upload( 52 | $photoFilename, 53 | $title = null, 54 | $description = null, 55 | $tags = null, 56 | $isPublic = null, 57 | $isFriend = null, 58 | $isFamily = null, 59 | $contentType = null, 60 | $hidden = null, 61 | $async = false 62 | ) { 63 | $params = [ 64 | 'title' => $title, 65 | 'description' => $description, 66 | 'tags' => $tags, 67 | 'is_public' => $isPublic, 68 | 'is_friend' => $isFriend, 69 | 'is_family' => $isFamily, 70 | 'content_type' => $contentType, 71 | 'hidden' => $hidden, 72 | ]; 73 | if ($async) { 74 | $params['async'] = 1; 75 | } 76 | return $this->sendFile($photoFilename, $params); 77 | } 78 | 79 | /** 80 | * @link https://www.flickr.com/services/api/replace.api.html 81 | * @param string $photoFilename Full filesystem path to the file to upload. 82 | * @param int $photoId The ID of the photo to replace. 83 | * @param bool $async Photos may be replaced in async mode, for applications that don't want to 84 | * wait around for an upload to complete, leaving a socket connection open the whole time. 85 | * Processing photos asynchronously is recommended. 86 | * @return string[] 87 | */ 88 | public function replace($photoFilename, $photoId, $async = null) 89 | { 90 | return $this->sendFile($photoFilename, ['photo_id' => $photoId, 'async' => $async]); 91 | } 92 | 93 | /** 94 | * @param string $filename 95 | * @param array $params 96 | * @return array 97 | * @throws Exception If an OAuth error occurs. 98 | * @throws FlickrException If the file can't be read. 99 | */ 100 | protected function sendFile($filename, $params) 101 | { 102 | if (!is_readable($filename)) { 103 | throw new FlickrException("File not readable: $filename"); 104 | } 105 | $args = $this->flickr 106 | ->getOauthService() 107 | ->getAuthorizationForPostingToAlternateUrl($params, $this->uploadEndpoint); 108 | // The 'photo' parameter can't be part of the authorization signature, so we add it now. 109 | $args['photo'] = new CURLFile(realpath($filename)); 110 | 111 | $curl = curl_init($this->uploadEndpoint); 112 | curl_setopt($curl, CURLOPT_POST, true); 113 | curl_setopt($curl, CURLOPT_POSTFIELDS, $args); 114 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 115 | curl_setopt($curl, CURLOPT_USERAGENT, $this->flickr->getUserAgent()); 116 | $response = curl_exec($curl); 117 | $this->response = $response; 118 | curl_close($curl); 119 | 120 | // Some OAuth errors are not in an XML format, but instead look 121 | // like e.g. oauth_problem=token_rejected 122 | if (1 === preg_match('/oauth_problem=(.*)/', $response, $matches)) { 123 | throw new OauthException($matches[1]); 124 | } 125 | 126 | // Process result. 127 | $xml = simplexml_load_string($response); 128 | $uploadResponse = ['stat' => (string)$xml['stat'][0]]; 129 | if (isset($xml->photoid)) { 130 | $uploadResponse['photoid'] = (int)$xml->photoid; 131 | } 132 | if (isset($xml->photoid['secret'])) { 133 | $uploadResponse['secret'] = (string)$xml->photoid['secret']; 134 | } 135 | if (isset($xml->photoid['originalsecret'])) { 136 | $uploadResponse['originalsecret'] = (string)$xml->photoid['originalsecret']; 137 | } 138 | if (isset($xml->ticketid)) { 139 | $uploadResponse['ticketid'] = (string)$xml->ticketid; 140 | } 141 | if (isset($xml->err)) { 142 | $uploadResponse['code'] = (int)$xml->err['code']; 143 | $uploadResponse['message'] = (string)$xml->err['msg']; 144 | } 145 | return $uploadResponse; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/FavoritesApi.php: -------------------------------------------------------------------------------- 1 | $photoId 20 | ]; 21 | return $this->flickr->request('flickr.favorites.add', $params); 22 | } 23 | 24 | /** 25 | * Returns next and previous favorites for a photo in a user's favorites. 26 | * 27 | * This method does not require authentication. 28 | * 29 | * @link https://www.flickr.com/services/api/flickr.favorites.getContext.html 30 | * @param string $photoId The id of the photo to fetch the context for. 31 | * @param string $userId The user who counts the photo as a favorite. 32 | * @return 33 | */ 34 | public function getContext($photoId, $userId) 35 | { 36 | $params = [ 37 | 'photo_id' => $photoId, 38 | 'user_id' => $userId 39 | ]; 40 | return $this->flickr->request('flickr.favorites.getContext', $params); 41 | } 42 | 43 | /** 44 | * Returns a list of the user's favorite photos. Only photos which the calling user 45 | * has permission to see are returned. 46 | * 47 | * This method does not require authentication. 48 | * 49 | * @link https://www.flickr.com/services/api/flickr.favorites.getList.html 50 | * @param string $userId The NSID of the user to fetch the favorites list for. If 51 | * this argument is omitted, the favorites list for the calling user is returned. 52 | * @param string $minFaveDate Minimum date that a photo was favorited on. The date 53 | * should be in the form of a unix timestamp. 54 | * @param string $maxFaveDate Maximum date that a photo was favorited on. The date 55 | * should be in the form of a unix timestamp. 56 | * @param string $extras A comma-delimited list of extra information to fetch for 57 | * each returned record. Currently supported fields are: description, 58 | * license, date_upload, date_taken, 59 | * owner_name, icon_server, original_format, 60 | * last_update, geo, tags, 61 | * machine_tags, o_dims, views, 62 | * media, path_alias, url_sq, 63 | * url_t, url_s, url_q, url_m, 64 | * url_n, url_z, url_c, url_l, 65 | * url_o 66 | * @param string $perPage Number of photos to return per page. If this argument is 67 | * omitted, it defaults to 100. The maximum allowed value is 500. 68 | * @param string $page The page of results to return. If this argument is omitted, 69 | * it defaults to 1. 70 | * @return 71 | */ 72 | public function getList( 73 | $userId = null, 74 | $minFaveDate = null, 75 | $maxFaveDate = null, 76 | $extras = null, 77 | $perPage = null, 78 | $page = null 79 | ) { 80 | $params = [ 81 | 'user_id' => $userId, 82 | 'min_fave_date' => $minFaveDate, 83 | 'max_fave_date' => $maxFaveDate, 84 | 'extras' => $extras, 85 | 'per_page' => $perPage, 86 | 'page' => $page 87 | ]; 88 | return $this->flickr->request('flickr.favorites.getList', $params); 89 | } 90 | 91 | /** 92 | * Returns a list of favorite public photos for the given user. 93 | * 94 | * This method does not require authentication. 95 | * 96 | * @link https://www.flickr.com/services/api/flickr.favorites.getPublicList.html 97 | * @param string $userId The user to fetch the favorites list for. 98 | * @param string $minFaveDate Minimum date that a photo was favorited on. The date 99 | * should be in the form of a unix timestamp. 100 | * @param string $maxFaveDate Maximum date that a photo was favorited on. The date 101 | * should be in the form of a unix timestamp. 102 | * @param string $extras A comma-delimited list of extra information to fetch for 103 | * each returned record. Currently supported fields are: description, 104 | * license, date_upload, date_taken, 105 | * owner_name, icon_server, original_format, 106 | * last_update, geo, tags, 107 | * machine_tags, o_dims, views, 108 | * media, path_alias, url_sq, 109 | * url_t, url_s, url_q, url_m, 110 | * url_n, url_z, url_c, url_l, 111 | * url_o 112 | * @param string $perPage Number of photos to return per page. If this argument is 113 | * omitted, it defaults to 100. The maximum allowed value is 500. 114 | * @param string $page The page of results to return. If this argument is omitted, 115 | * it defaults to 1. 116 | * @return 117 | */ 118 | public function getPublicList( 119 | $userId, 120 | $minFaveDate = null, 121 | $maxFaveDate = null, 122 | $extras = null, 123 | $perPage = null, 124 | $page = null 125 | ) { 126 | $params = [ 127 | 'user_id' => $userId, 128 | 'min_fave_date' => $minFaveDate, 129 | 'max_fave_date' => $maxFaveDate, 130 | 'extras' => $extras, 131 | 'per_page' => $perPage, 132 | 'page' => $page 133 | ]; 134 | return $this->flickr->request('flickr.favorites.getPublicList', $params); 135 | } 136 | 137 | /** 138 | * Removes a photo from a user's favorites list. 139 | * 140 | * This method requires authentication. 141 | * 142 | * @link https://www.flickr.com/services/api/flickr.favorites.remove.html 143 | * @param string $photoId The id of the photo to remove from the user's favorites. 144 | * @return 145 | */ 146 | public function remove($photoId) 147 | { 148 | $params = [ 149 | 'photo_id' => $photoId 150 | ]; 151 | return $this->flickr->request('flickr.favorites.remove', $params); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/PushApi.php: -------------------------------------------------------------------------------- 1 | flickr->request('flickr.push.getSubscriptions'); 19 | } 20 | 21 | /** 22 | * All the different flavours of anteater. This method is experimental and may change. 23 | * 24 | * This method does not require authentication. 25 | * 26 | * @link https://www.flickr.com/services/api/flickr.push.getTopics.html 27 | * 28 | * @return 29 | */ 30 | public function getTopics() 31 | { 32 | return $this->flickr->request('flickr.push.getTopics'); 33 | } 34 | 35 | /** 36 | * In ur pandas, tickling ur unicorn 37 |

    38 | (this method is experimental and 39 | * may change) 40 | * 41 | * This method requires authentication. 42 | * 43 | * @link https://www.flickr.com/services/api/flickr.push.subscribe.html 44 | * @param string $topic The type of subscription. See flickr.push.getTopics. 46 | * @param string $callback The url for the subscription endpoint. Limited to 255 47 | * bytes, and must be unique for this user, i.e. no two subscriptions for a given 48 | * user may use the same callback url. 49 | * @param string $verify The verification mode, either sync or 50 | * async. See the Google 52 | * PubSubHubbub spec for details. 53 | * @param string $verifyToken The verification token to be echoed back to the 54 | * subscriber during the verification callback, as per the Google 56 | * PubSubHubbub spec. Limited to 200 bytes. 57 | * @param string $leaseSeconds Number of seconds for which the subscription will be 58 | * valid. Legal values are 60 to 86400 (1 minute to 1 day). If not present, the 59 | * subscription will be auto-renewing. 60 | * @param string $woeIds A 32-bit integer for a Where on Earth ID. Only 62 | * valid if topic is geo.

    The order of 63 | * precedence for geo subscriptions is : woe ids, place ids, radial i.e. the 64 | * lat, lon parameters will be ignored if place_ids is 65 | * present, which will be ignored if woe_ids is present. 66 | * @param string $placeIds A comma-separated list of Flickr place IDs. Only valid 67 | * if topic is geo.

    The order of precedence 68 | * for geo subscriptions is : woe ids, place ids, radial i.e. the lat, 69 | * lon parameters will be ignored if place_ids is present, 70 | * which will be ignored if woe_ids is present. 71 | * @param string $lat A latitude value, in decimal format. Only valid if 72 | * topic is geo. Defines the latitude for a radial query 73 | * centered around (lat, lon).

    The order of precedence for geo 74 | * subscriptions is : woe ids, place ids, radial i.e. the lat, lon 75 | * parameters will be ignored if place_ids is present, which will be 76 | * ignored if woe_ids is present. 77 | * @param string $lon A longitude value, in decimal format. Only valid if 78 | * topic is geo. Defines the longitude for a radial query 79 | * centered around (lat, lon).

    The order of precedence for geo 80 | * subscriptions is : woe ids, place ids, radial i.e. the lat, lon 81 | * parameters will be ignored if place_ids is present, which will be 82 | * ignored if woe_ids is present. 83 | * @param string $radius A radius value, in the units defined by radius_units. Only 84 | * valid if topic is geo. Defines the radius of a circle 85 | * for a radial query centered around (lat, lon). Default is 5 km.

    The 86 | * order of precedence for geo subscriptions is : woe ids, place ids, radial i.e. 87 | * the lat, lon parameters will be ignored if place_ids 88 | * is present, which will be ignored if woe_ids is present. 89 | * @param string $radiusUnits Defines the units for the radius parameter. Only 90 | * valid if topic is geo. Options are mi and 91 | * km. Default is km.

    The order of precedence 92 | * for geo subscriptions is : woe ids, place ids, radial i.e. the lat, 93 | * lon parameters will be ignored if place_ids is present, 94 | * which will be ignored if woe_ids is present. 95 | * @param string $accuracy Defines the minimum accuracy required for photos to be 96 | * included in a subscription. Only valid if topic is geo 97 | * Legal values are 1-16, default is 1 (i.e. any accuracy level). 100 | * @param string $nsids A comma-separated list of nsids representing Flickr Commons 101 | * institutions (see flickr.commons.getInstitutions). 103 | * Only valid if topic is commons. If not present this 104 | * argument defaults to all Flickr Commons institutions. 105 | * @param string $tags A comma-separated list of strings to be used for tag 106 | * subscriptions. Photos with one or more of the tags listed will be included in 107 | * the subscription. Only valid if the topic is tags. 108 | * @return 109 | */ 110 | public function subscribe( 111 | $topic, 112 | $callback, 113 | $verify, 114 | $verifyToken = null, 115 | $leaseSeconds = null, 116 | $woeIds = null, 117 | $placeIds = null, 118 | $lat = null, 119 | $lon = null, 120 | $radius = null, 121 | $radiusUnits = null, 122 | $accuracy = null, 123 | $nsids = null, 124 | $tags = null 125 | ) { 126 | $params = [ 127 | 'topic' => $topic, 128 | 'callback' => $callback, 129 | 'verify' => $verify, 130 | 'verify_token' => $verifyToken, 131 | 'lease_seconds' => $leaseSeconds, 132 | 'woe_ids' => $woeIds, 133 | 'place_ids' => $placeIds, 134 | 'lat' => $lat, 135 | 'lon' => $lon, 136 | 'radius' => $radius, 137 | 'radius_units' => $radiusUnits, 138 | 'accuracy' => $accuracy, 139 | 'nsids' => $nsids, 140 | 'tags' => $tags 141 | ]; 142 | return $this->flickr->request('flickr.push.subscribe', $params); 143 | } 144 | 145 | /** 146 | * Why would you want to do this? 147 |

    148 | (this method is experimental and may 149 | * change) 150 | * 151 | * This method requires authentication. 152 | * 153 | * @link https://www.flickr.com/services/api/flickr.push.unsubscribe.html 154 | * @param string $topic The type of subscription. See flickr.push.getTopics. 156 | * @param string $callback The url for the subscription endpoint (must be the same 157 | * url as was used when creating the subscription). 158 | * @param string $verify The verification mode, either 'sync' or 'async'. See the 159 | * Google 161 | * PubSubHubbub spec for details. 162 | * @param string $verifyToken The verification token to be echoed back to the 163 | * subscriber during the verification callback, as per the Google 165 | * PubSubHubbub spec. Limited to 200 bytes. 166 | * @return 167 | */ 168 | public function unsubscribe($topic, $callback, $verify, $verifyToken = null) 169 | { 170 | $params = [ 171 | 'topic' => $topic, 172 | 'callback' => $callback, 173 | 'verify' => $verify, 174 | 'verify_token' => $verifyToken 175 | ]; 176 | return $this->flickr->request('flickr.push.unsubscribe', $params); 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/TestimonialsApi.php: -------------------------------------------------------------------------------- 1 | $userId, 22 | 'testimonial_text' => $testimonialText 23 | ]; 24 | return $this->flickr->request('flickr.testimonials.addTestimonial', $params); 25 | } 26 | 27 | /** 28 | * Approve a testimonial that has been written about the currently loggedin user 29 | * 30 | * This method requires authentication. 31 | * 32 | * @link https://www.flickr.com/services/api/flickr.testimonials.approveTestimonial.html 33 | * @param string $testimonialId ID of the testimonial to approve 34 | * @return 35 | */ 36 | public function approveTestimonial($testimonialId) 37 | { 38 | $params = [ 39 | 'testimonial_id' => $testimonialId 40 | ]; 41 | return $this->flickr->request('flickr.testimonials.approveTestimonial', $params); 42 | } 43 | 44 | /** 45 | * Permanently delete a testimonial. The loggedin user must be either the author or 46 | * recipient of the testimonial 47 | * 48 | * This method requires authentication. 49 | * 50 | * @link https://www.flickr.com/services/api/flickr.testimonials.deleteTestimonial.html 51 | * @param string $testimonialId 52 | * @return 53 | */ 54 | public function deleteTestimonial($testimonialId) 55 | { 56 | $params = [ 57 | 'testimonial_id' => $testimonialId 58 | ]; 59 | return $this->flickr->request('flickr.testimonials.deleteTestimonial', $params); 60 | } 61 | 62 | /** 63 | * Change the text of a testimonial. The loggedin user must be the author of the 64 | * existing testimonial. Editing a testimonial will mark it as pending and will 65 | * require it to be re-approved by the recipient before appearing on their profile 66 | * 67 | * This method requires authentication. 68 | * 69 | * @link https://www.flickr.com/services/api/flickr.testimonials.editTestimonial.html 70 | * @param string $userId The NSID of the user the testimonial is about 71 | * @param string $testimonialId The ID of the testimonial to edit 72 | * @param string $testimonialText The text of the testimonial. HTML/BBCode is not 73 | * accepted 74 | * @return 75 | */ 76 | public function editTestimonial($userId, $testimonialId, $testimonialText) 77 | { 78 | $params = [ 79 | 'user_id' => $userId, 80 | 'testimonial_id' => $testimonialId, 81 | 'testimonial_text' => $testimonialText 82 | ]; 83 | return $this->flickr->request('flickr.testimonials.editTestimonial', $params); 84 | } 85 | 86 | /** 87 | * Get all testimonials (pending and approved) written about the given user 88 | * 89 | * This method requires authentication. 90 | * 91 | * @link https://www.flickr.com/services/api/flickr.testimonials.getAllTestimonialsAbout.html 92 | * @param string $page Page number. Default is 0 93 | * @param string $perPage Number of testimonials to return per page. Default is 10, 94 | * maximum is 50 95 | * @return 96 | */ 97 | public function getAllTestimonialsAbout($page = null, $perPage = null) 98 | { 99 | $params = [ 100 | 'page' => $page, 101 | 'per_page' => $perPage 102 | ]; 103 | return $this->flickr->request('flickr.testimonials.getAllTestimonialsAbout', $params); 104 | } 105 | 106 | /** 107 | * Get the testimonial by the currently logged-in user about the given user, 108 | * regardless of approval status. Note that at most 1 testimonial will be returned 109 | * 110 | * This method requires authentication. 111 | * 112 | * @link https://www.flickr.com/services/api/flickr.testimonials.getAllTestimonialsAboutBy.html 113 | * @param string $userId ID of the user to get testimonials about 114 | * @return 115 | */ 116 | public function getAllTestimonialsAboutBy($userId) 117 | { 118 | $params = [ 119 | 'user_id' => $userId 120 | ]; 121 | return $this->flickr->request('flickr.testimonials.getAllTestimonialsAboutBy', $params); 122 | } 123 | 124 | /** 125 | * Get all testimonials (pending and approved) written by the given user 126 | * 127 | * This method requires authentication. 128 | * 129 | * @link https://www.flickr.com/services/api/flickr.testimonials.getAllTestimonialsBy.html 130 | * @param string $page Page number. Default is 0 131 | * @param string $perPage Number of testimonials to return per page. Default is 10, 132 | * maximum is 50 133 | * @return 134 | */ 135 | public function getAllTestimonialsBy($page = null, $perPage = null) 136 | { 137 | $params = [ 138 | 'page' => $page, 139 | 'per_page' => $perPage 140 | ]; 141 | return $this->flickr->request('flickr.testimonials.getAllTestimonialsBy', $params); 142 | } 143 | 144 | /** 145 | * Get all pending testimonials written about the given user 146 | * 147 | * This method requires authentication. 148 | * 149 | * @link https://www.flickr.com/services/api/flickr.testimonials.getPendingTestimonialsAbout.html 150 | * @param string $page Page number. Default is 0 151 | * @param string $perPage Number of testimonials to return per page. Default is 10, 152 | * maximum is 50 153 | * @return 154 | */ 155 | public function getPendingTestimonialsAbout($page = null, $perPage = null) 156 | { 157 | $params = [ 158 | 'page' => $page, 159 | 'per_page' => $perPage 160 | ]; 161 | return $this->flickr->request('flickr.testimonials.getPendingTestimonialsAbout', $params); 162 | } 163 | 164 | /** 165 | * Get the pending testimonial by the currently logged-in user about the given 166 | * user. Note that at most 1 testimonial will be returned 167 | * 168 | * This method requires authentication. 169 | * 170 | * @link https://www.flickr.com/services/api/flickr.testimonials.getPendingTestimonialsAboutBy.html 171 | * @param string $userId ID of the user to get testimonials about 172 | * @return 173 | */ 174 | public function getPendingTestimonialsAboutBy($userId) 175 | { 176 | $params = [ 177 | 'user_id' => $userId 178 | ]; 179 | return $this->flickr->request('flickr.testimonials.getPendingTestimonialsAboutBy', $params); 180 | } 181 | 182 | /** 183 | * Get all pending testimonials written by the given user 184 | * 185 | * This method requires authentication. 186 | * 187 | * @link https://www.flickr.com/services/api/flickr.testimonials.getPendingTestimonialsBy.html 188 | * @param string $page Page number. Default is 0 189 | * @param string $perPage Number of testimonials to return per page. Default is 10, 190 | * maximum is 50 191 | * @return 192 | */ 193 | public function getPendingTestimonialsBy($page = null, $perPage = null) 194 | { 195 | $params = [ 196 | 'page' => $page, 197 | 'per_page' => $perPage 198 | ]; 199 | return $this->flickr->request('flickr.testimonials.getPendingTestimonialsBy', $params); 200 | } 201 | 202 | /** 203 | * Get approved testimonials about the given user 204 | * 205 | * This method does not require authentication. 206 | * 207 | * @link https://www.flickr.com/services/api/flickr.testimonials.getTestimonialsAbout.html 208 | * @param string $userId ID of the user to get testimonials about 209 | * @param string $page Page number. Default is 0 210 | * @param string $perPage Number of testimonials to return per page. Default is 10, 211 | * maximum is 50 212 | * @return 213 | */ 214 | public function getTestimonialsAbout($userId, $page = null, $perPage = null) 215 | { 216 | $params = [ 217 | 'user_id' => $userId, 218 | 'page' => $page, 219 | 'per_page' => $perPage 220 | ]; 221 | return $this->flickr->request('flickr.testimonials.getTestimonialsAbout', $params); 222 | } 223 | 224 | /** 225 | * Get the approved testimonial by the currently logged-in user about the given 226 | * user. Note that at most 1 testimonial will be returned 227 | * 228 | * This method requires authentication. 229 | * 230 | * @link https://www.flickr.com/services/api/flickr.testimonials.getTestimonialsAboutBy.html 231 | * @param string $userId ID of the user to get testimonials about 232 | * @return 233 | */ 234 | public function getTestimonialsAboutBy($userId) 235 | { 236 | $params = [ 237 | 'user_id' => $userId 238 | ]; 239 | return $this->flickr->request('flickr.testimonials.getTestimonialsAboutBy', $params); 240 | } 241 | 242 | /** 243 | * Get approved testimonials written by the given user 244 | * 245 | * This method does not require authentication. 246 | * 247 | * @link https://www.flickr.com/services/api/flickr.testimonials.getTestimonialsBy.html 248 | * @param string $userId ID of the user to get testimonials written by 249 | * @param string $page Page number. Default is 0 250 | * @param string $perPage Number of testimonials to return per page. Default is 10, 251 | * maximum is 50 252 | * @return 253 | */ 254 | public function getTestimonialsBy($userId, $page = null, $perPage = null) 255 | { 256 | $params = [ 257 | 'user_id' => $userId, 258 | 'page' => $page, 259 | 'per_page' => $perPage 260 | ]; 261 | return $this->flickr->request('flickr.testimonials.getTestimonialsBy', $params); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PhpFlickr 2 | ========= 3 | 4 | A PHP wrapper for the Flickr API. 5 | 6 | https://github.com/samwilson/phpflickr 7 | 8 | [![Packagist](https://img.shields.io/packagist/v/samwilson/phpflickr.svg)](https://packagist.org/packages/samwilson/phpflickr) 9 | 10 | [![Build status](https://github.com/samwilson/phpflickr/workflows/CI/badge.svg)](https://github.com/samwilson/phpflickr/actions/workflows/ci.yml) 11 | 12 | Table of contents: 13 | 14 | * [Installation](#installation) 15 | * [Usage](#usage) 16 | * [Examples](#examples) 17 | * [Authentication](#authentication) 18 | * [Making authenticated requests](#making-authenticated-requests) 19 | * [Caching](#caching) 20 | * [Proxy server](#proxy-server) 21 | * [Uploading](#uploading) 22 | * [Kudos](#kudos) 23 | 24 | ## Installation 25 | 26 | Install with [Composer](https://getcomposer.org/): 27 | 28 | composer require samwilson/phpflickr 29 | 30 | Alternatively, Symfony developers can install [a bundle](https://github.com/survos/SurvosFlickrBundle): 31 | 32 | composer require survos/flickr-bundle 33 | 34 | After setting the API key and secret in the environment, 35 | you can inject the `FlickrService` into your controller or service, 36 | rather than instantiating a PhpFlickr object as described below. 37 | 38 | ## Usage 39 | 40 | Once you've included Composer's autoloader, create a PhpFlickr object. 41 | For example: 42 | 43 | ```php 44 | require_once 'vendor/autoload.php'; 45 | $flickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret); 46 | ``` 47 | 48 | The constructor takes two arguments: 49 | 50 | 1. `$apiKey` — This is the API key given to you by Flickr 51 | when you [register an app](https://www.flickr.com/services/api/keys/). 52 | 53 | 2. `$secret` — The API secret is optional because it is only required to 54 | make authenticated requests ([see below](#making-authenticated-requests)). 55 | It is given to you along with your API key when you register an app. 56 | 57 | All of the API methods have been implemented in phpFlickr. You can 58 | see a full list and documentation here: 59 | http://www.flickr.com/services/api/ 60 | 61 | To call a method, remove the "flickr." part of the name and replace 62 | any periods with underscores. For example, instead of 63 | flickr.photos.search, you would call $f->photos_search() or instead 64 | of flickr.photos.licenses.getInfo, you would call 65 | $f->photos_licenses_getInfo() (yes, it is case sensitive). 66 | 67 | All functions have their arguments implemented in the list order on 68 | their documentation page (a link to which is included with each 69 | method in the phpFlickr clasS). The only exceptions to this are 70 | photos_search(), photos_getWithoutGeodata() and 71 | photos_getWithoutGeodata() which have so many optional arguments 72 | that it's easier for everyone if you just have to pass an 73 | associative array of arguments. See the comment in the 74 | photos_search() definition in phpFlickr.php for more information. 75 | 76 | ## Examples 77 | 78 | There are a few example files in the `examples/` directory. 79 | To use these, first copy `examples/config.dist.php` to `examples/config.php` 80 | and run `php examples/get_auth_token.php` to get the access token. 81 | Add this access token to your `examples/config.php` 82 | and then you can run any of the examples that require authentication 83 | (note that not all of them do). 84 | 85 | ## Authentication 86 | 87 | There is only one user authentication method available to the API, and that is OAuth 1.0. 88 | You only need to use this if you're performing operations that require it, 89 | such as uploading or accessing private photos. 90 | 91 | This authentication method is somewhat complex, 92 | but is secure and allows your users to feel a little safer authenticating to your application. 93 | You don't have to ask for their username and password. 94 | 95 | ☛ *Read more about the [Flickr Authentication API](https://www.flickr.com/services/api/auth.oauth.html).* 96 | 97 | We know how difficult this API looks at first glance, 98 | so we've tried to make it as transparent as possible for users of phpFlickr. 99 | We'll go through all of the steps you'll need to do to use this. 100 | 101 | To have end users authenticate their accounts: 102 | 103 | 1. Create an object in which to temporarily store the authentication token, 104 | and give it to PhpFlickr. 105 | This must be an implementation of TokenStorageInterface, 106 | and will usually be of type `Session` (for browser-based workflows) 107 | or `Memory` (for command-line workflows) 108 | — or you can create your own implementation. 109 | 110 | ```php 111 | $storage = new \OAuth\Common\Storage\Memory(); 112 | $flickr->setOauthStorage($storage); 113 | ``` 114 | 115 | 2. Send your user to a Flickr URL (by redirecting them, or just telling them to click a link), 116 | where they'll confirm that they want your application to have the permission you specify 117 | (which is either `read`, `write`, or `delete`). 118 | 119 | ```php 120 | $perm = 'read'; 121 | $url = $flickr->getAuthUrl($perm, $callbackUrl); 122 | ``` 123 | 124 | 3. Once the user has authorized your application, they'll 125 | either be redirected back to a URL on your site (that you specified as the callback URL above) 126 | or be given a nine-digit code that they'll need to copy and paste into your application. 127 | 128 | 1. For the browser-based workflow, your callback URL will now have 129 | two new query-string parameters: `oauth_token` and `oauth_verifier`. 130 | 2. For CLI workflow, you'll need to strip anything other than digits from the string that the user gives you 131 | (e.g. leading and trailing spaces, and the hyphens in the code). 132 | 133 | 4. You can now request the final 'access token': 134 | 135 | 1. For the browser-based workflow: 136 | ```php 137 | $accessToken = $flickr->retrieveAccessToken($_GET['oauth_verifier'], $_GET['oauth_token']); 138 | ``` 139 | 2. For the CLI workflow, it's much the same, 140 | but because you've still got access to the request token 141 | you can leave it out when you run this request: 142 | ```php 143 | $verifier = '<9-digit code stripped of hyphens and spaces>'; 144 | $accessToken = $flickr->retrieveAccessToken($verifier); 145 | ``` 146 | 147 | 5. Now you can save the two string parts of the access token 148 | (which you can get via 149 | the `$accessToken->getAccessToken()` and `$accessToken->getAccessTokenSecret()` methods) 150 | and use this for future requests. 151 | The access token doesn't expire, and must be stored securely 152 | (the details of doing that are outside the scope of PhpFlickr). 153 | 154 | ## Making authenticated requests 155 | 156 | Once you have an access token (see [above](#authentication)), 157 | you can store it somewhere secure and use it to make authenticated requests at a later time. 158 | To do this, first create a storage object 159 | (again, as for the initial authentication process, you can choose between different storage types, 160 | but for many situations the in-memory storage is sufficient), 161 | and then store your access token in that object: 162 | 163 | ```php 164 | // Create storage. 165 | $storage = new \OAuth\Common\Storage\Memory(); 166 | // Create the access token from the strings you acquired before. 167 | $token = new \OAuth\OAuth1\Token\StdOAuth1Token(); 168 | $token->setAccessToken($accessToken); 169 | $token->setAccessTokenSecret($accessTokenSecret); 170 | // Add the token to the storage. 171 | $storage->storeAccessToken('Flickr', $token); 172 | ``` 173 | 174 | Now, you can pass the storage into PhpFlickr, and start making requests: 175 | 176 | ```php 177 | $flickr->setOauthStorage($storage); 178 | $recent = $phpFlickr->photos()->getContactsPhotos(); 179 | ``` 180 | 181 | See the [Usage section](#usage) above for more details on the request methods, 182 | and the `examples/recent_photos.php` file for a working example. 183 | 184 | ## Caching 185 | 186 | PhpFlickr can be used with any PSR-6 compatible cache, such as 187 | [symfony/cache](https://packagist.org/packages/symfony/cache) 188 | or [tedivm/stash](https://packagist.org/packages/tedivm/stash). 189 | 190 | To enable caching, pass a configured cache object to `PhpFlickr::setCache($cacheItemPool)`. 191 | 192 | All requests are cached for the same time duration, which by default is 10 minutes. 193 | This can be changed with the `PhpFlickr::setCacheDefaultExpiry()`. 194 | 195 | ## Uploading 196 | 197 | ### Uploading new photos 198 | 199 | Uploading is pretty simple. Aside from being authenticated 200 | (see the [Authentication](#Authentication) section above) 201 | the very minimum that you'll have to pass is a path to an image file. 202 | You can upload a file as follows: 203 | 204 | ```php 205 | $flickr->uploader()->upload('/path/to/photo.jpg'); 206 | ``` 207 | 208 | The other upload parameters are documented in the method's docblock. 209 | One useful one is the `$async` flag, which permits *asyncronous* uploading, 210 | which means that, rather than uploading the file immediately and before returning, 211 | a 'ticket ID' is returned, with which you can subsequently fetch the upload's status. 212 | You can read more about asynchronous uploading 213 | in [Flickr's API documentation](https://www.flickr.com/services/api/upload.async.html). 214 | 215 | ### Replacing existing photos 216 | 217 | You can also upload a photo as a replacement to an existing photo. 218 | 219 | ```php 220 | $flickr->uploader()->replace('/path/to/photo.jpg', 44333812150); 221 | ``` 222 | 223 | This method doesn't allow for setting any photo metadata, 224 | but you can do the replacement asynchronously 225 | (in which case a 'ticket ID' will be returned). 226 | 227 | ## User Agent 228 | 229 | If you are using PhpFlickr in an application, it is a good idea to set a custom user agent. 230 | This can be done with the following: 231 | 232 | ```php 233 | $flickr->setUserAgent('MyVendor-MyApp/1.0.0'); 234 | ``` 235 | 236 | ## Proxy server 237 | 238 | PhpFlickr can be used with a proxy server 239 | or any service that matches Flickr's API (such as [23 Photo Sharing](http://www.23hq.com)). 240 | To use this feature, pass the proxy server's base URL after instantiating a PhpFlickr object. 241 | For example: 242 | 243 | ```php 244 | $flickr->setProxyBaseUrl('http://localhost:8181/flickr'); 245 | ``` 246 | 247 | After that, all requests will be automatically made through your proxy server. 248 | 249 | One example of configuring such a proxy service, for the Apache webserver, is as follows: 250 | 251 | ``` 252 | ProxyRequests Off 253 | SSLProxyEngine on 254 | ProxyPass /flickr https://api.flickr.com/services 255 | ProxyPassReverse /flickr https://api.flickr.com/services 256 | ``` 257 | 258 | ## Kudos 259 | 260 | This is a fork of Dan Coulter's original [phpFlickr](https://github.com/dan-coulter/phpflickr) 261 | library, maintained by Sam Wilson. All the hard work was done by Dan! 262 | 263 | Thanks also is greatly due to the many other 264 | [contributors](https://github.com/samwilson/phpflickr/graphs/contributors). 265 | 266 | The [Agateware_Example.JPG](https://commons.wikimedia.org/wiki/File:Agateware_Example.JPG) 267 | used for the upload examples is [CC-BY-SA](https://creativecommons.org/licenses/by-sa/4.0) 268 | by User:Anonymouse512, via Wikimedia Commons. 269 | -------------------------------------------------------------------------------- /src/PhotosGeoApi.php: -------------------------------------------------------------------------------- 1 |
    10 | 11 | Batch corrections are processed in a 12 | * delayed queue so it may take a few minutes before the changes are reflected in a 13 | * user's photos. 14 | * 15 | * This method requires authentication. 16 | * 17 | * @link https://www.flickr.com/services/api/flickr.photos.geo.batchCorrectLocation.html 18 | * @param string $lat The latitude of the photos to be update whose valid range is 19 | * -90 to 90. Anything more than 6 decimal places will be truncated. 20 | * @param string $lon The longitude of the photos to be updated whose valid range 21 | * is -180 to 180. Anything more than 6 decimal places will be truncated. 22 | * @param string $accuracy Recorded accuracy level of the photos to be updated. 23 | * World level is 1, Country is ~3, Region ~6, City ~11, Street ~16. Current range 24 | * is 1-16. Defaults to 16 if not specified. 25 | * @param string $placeId A Flickr Places ID. (While optional, you must pass either 26 | * a valid Places ID or a WOE ID.) 27 | * @param string $woeId A Where On Earth (WOE) ID. (While optional, you must pass 28 | * either a valid Places ID or a WOE ID.) 29 | * @return 30 | */ 31 | public function batchCorrectLocation($lat, $lon, $accuracy, $placeId = null, $woeId = null) 32 | { 33 | $params = [ 34 | 'lat' => $lat, 35 | 'lon' => $lon, 36 | 'accuracy' => $accuracy, 37 | 'place_id' => $placeId, 38 | 'woe_id' => $woeId 39 | ]; 40 | return $this->flickr->request('flickr.photos.geo.batchCorrectLocation', $params); 41 | } 42 | 43 | /** 44 | * This method requires authentication. 45 | * 46 | * @link https://www.flickr.com/services/api/flickr.photos.geo.correctLocation.html 47 | * @param string $photoId The ID of the photo whose WOE location is being 48 | * corrected. 49 | * @param string $foursquareId The venue ID for a Foursquare location. (If not 50 | * passed in with correction, any existing foursquare venue will be removed). 51 | * @param string $placeId A Flickr Places ID. (While optional, you must pass either 52 | * a valid Places ID or a WOE ID.) 53 | * @param string $woeId A Where On Earth (WOE) ID. (While optional, you must pass 54 | * either a valid Places ID or a WOE ID.) 55 | * @return 56 | */ 57 | public function correctLocation($photoId, $foursquareId, $placeId = null, $woeId = null) 58 | { 59 | $params = [ 60 | 'photo_id' => $photoId, 61 | 'place_id' => $placeId, 62 | 'woe_id' => $woeId, 63 | 'foursquare_id' => $foursquareId 64 | ]; 65 | return $this->flickr->request('flickr.photos.geo.correctLocation', $params); 66 | } 67 | 68 | /** 69 | * Get the geo data (latitude and longitude and the accuracy level) for a photo. 70 | * 71 | * This method does not require authentication. 72 | * 73 | * @link https://www.flickr.com/services/api/flickr.photos.geo.getLocation.html 74 | * @param string $photoId The id of the photo you want to retrieve location data 75 | * for. 76 | * @param string $extras Extra flags. 77 | * @return 78 | */ 79 | public function getLocation($photoId, $extras = null) 80 | { 81 | $params = [ 82 | 'photo_id' => $photoId, 83 | 'extras' => $extras 84 | ]; 85 | return $this->flickr->request('flickr.photos.geo.getLocation', $params); 86 | } 87 | 88 | /** 89 | * Get permissions for who may view geo data for a photo. 90 | * 91 | * This method requires authentication. 92 | * 93 | * @link https://www.flickr.com/services/api/flickr.photos.geo.getPerms.html 94 | * @param string $photoId The id of the photo to get permissions for. 95 | * @return 96 | */ 97 | public function getPerms($photoId) 98 | { 99 | $params = [ 100 | 'photo_id' => $photoId 101 | ]; 102 | return $this->flickr->request('flickr.photos.geo.getPerms', $params); 103 | } 104 | 105 | /** 106 | * Return a list of photos for the calling user at a specific latitude, longitude 107 | * and accuracy 108 | * 109 | * This method requires authentication. 110 | * 111 | * @link https://www.flickr.com/services/api/flickr.photos.geo.photosForLocation.html 112 | * @param string $lat The latitude whose valid range is -90 to 90. Anything more 113 | * than 6 decimal places will be truncated. 114 | * @param string $lon The longitude whose valid range is -180 to 180. Anything more 115 | * than 6 decimal places will be truncated. 116 | * @param string $accuracy Recorded accuracy level of the location information. 117 | * World level is 1, Country is ~3, Region ~6, City ~11, Street ~16. Current range 118 | * is 1-16. Defaults to 16 if not specified. 119 | * @param string $extras A comma-delimited list of extra information to fetch for 120 | * each returned record. Currently supported fields are: description, 121 | * license, date_upload, date_taken, 122 | * owner_name, icon_server, original_format, 123 | * last_update, geo, tags, 124 | * machine_tags, o_dims, views, 125 | * media, path_alias, url_sq, 126 | * url_t, url_s, url_q, url_m, 127 | * url_n, url_z, url_c, url_l, 128 | * url_o 129 | * @param string $perPage Number of photos to return per page. If this argument is 130 | * omitted, it defaults to 100. The maximum allowed value is 500. 131 | * @param string $page The page of results to return. If this argument is omitted, 132 | * it defaults to 1. 133 | * @return 134 | */ 135 | public function photosForLocation($lat, $lon, $accuracy = null, $extras = null, $perPage = null, $page = null) 136 | { 137 | $params = [ 138 | 'lat' => $lat, 139 | 'lon' => $lon, 140 | 'accuracy' => $accuracy, 141 | 'extras' => $extras, 142 | 'per_page' => $perPage, 143 | 'page' => $page 144 | ]; 145 | return $this->flickr->request('flickr.photos.geo.photosForLocation', $params); 146 | } 147 | 148 | /** 149 | * Removes the geo data associated with a photo. 150 | * 151 | * This method requires authentication. 152 | * 153 | * @link https://www.flickr.com/services/api/flickr.photos.geo.removeLocation.html 154 | * @param string $photoId The id of the photo you want to remove location data 155 | * from. 156 | * @return 157 | */ 158 | public function removeLocation($photoId) 159 | { 160 | $params = [ 161 | 'photo_id' => $photoId 162 | ]; 163 | return $this->flickr->request('flickr.photos.geo.removeLocation', $params); 164 | } 165 | 166 | /** 167 | * Indicate the state of a photo's geotagginess beyond latitude and longitude.

    169 | Note : photos passed to this method must already be geotagged (using 170 | * the flickr.photos.geo.setLocation method). 171 | * 172 | * This method requires authentication. 173 | * 174 | * @link https://www.flickr.com/services/api/flickr.photos.geo.setContext.html 175 | * @param string $photoId The id of the photo to set context data for. 176 | * @param string $context Context is a numeric value representing the photo's 177 | * geotagginess beyond latitude and longitude. For example, you may wish to 178 | * indicate that a photo was taken "indoors" or "outdoors".

    The 179 | * current list of context IDs is :

    182 | * @return 183 | */ 184 | public function setContext($photoId, $context) 185 | { 186 | $params = [ 187 | 'photo_id' => $photoId, 188 | 'context' => $context 189 | ]; 190 | return $this->flickr->request('flickr.photos.geo.setContext', $params); 191 | } 192 | 193 | /** 194 | * Sets the geo data (latitude and longitude and, optionally, the accuracy level) 195 | * for a photo. 196 | 197 | Before users may assign location data to a photo they must define 198 | * who, by default, may view that information. Users can edit this preference at http://www.flickr.com/account/geo/privacy/. 200 | * If a user has not set this preference, the API method will return an error. 201 | * 202 | * This method requires authentication. 203 | * 204 | * @link https://www.flickr.com/services/api/flickr.photos.geo.setLocation.html 205 | * @param string $photoId The id of the photo to set location data for. 206 | * @param string $lat The latitude whose valid range is -90 to 90. Anything more 207 | * than 6 decimal places will be truncated. 208 | * @param string $lon The longitude whose valid range is -180 to 180. Anything more 209 | * than 6 decimal places will be truncated. 210 | * @param string $accuracy Recorded accuracy level of the location information. 211 | * World level is 1, Country is ~3, Region ~6, City ~11, Street ~16. Current range 212 | * is 1-16. Defaults to 16 if not specified. 213 | * @param string $context Context is a numeric value representing the photo's 214 | * geotagginess beyond latitude and longitude. For example, you may wish to 215 | * indicate that a photo was taken "indoors" or "outdoors".

    The 216 | * current list of context IDs is :


    The default context for geotagged photos is 0, or 219 | * "not defined" 220 | * @return 221 | */ 222 | public function setLocation($photoId, $lat, $lon, $accuracy = null, $context = null) 223 | { 224 | $params = [ 225 | 'photo_id' => $photoId, 226 | 'lat' => $lat, 227 | 'lon' => $lon, 228 | 'accuracy' => $accuracy, 229 | 'context' => $context 230 | ]; 231 | return $this->flickr->request('flickr.photos.geo.setLocation', $params); 232 | } 233 | 234 | /** 235 | * Set the permission for who may view the geo data associated with a photo. 236 | * 237 | * This method requires authentication. 238 | * 239 | * @link https://www.flickr.com/services/api/flickr.photos.geo.setPerms.html 240 | * @param string $isPublic 1 to set viewing permissions for the photo's location 241 | * data to public, 0 to set it to private. 242 | * @param string $isContact 1 to set viewing permissions for the photo's location 243 | * data to contacts, 0 to set it to private. 244 | * @param string $isFriend 1 to set viewing permissions for the photo's location 245 | * data to friends, 0 to set it to private. 246 | * @param string $isFamily 1 to set viewing permissions for the photo's location 247 | * data to family, 0 to set it to private. 248 | * @param string $photoId The id of the photo to get permissions for. 249 | * @return 250 | */ 251 | public function setPerms($isPublic, $isContact, $isFriend, $isFamily, $photoId) 252 | { 253 | $params = [ 254 | 'is_public' => $isPublic, 255 | 'is_contact' => $isContact, 256 | 'is_friend' => $isFriend, 257 | 'is_family' => $isFamily, 258 | 'photo_id' => $photoId 259 | ]; 260 | return $this->flickr->request('flickr.photos.geo.setPerms', $params); 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /src/PeopleApi.php: -------------------------------------------------------------------------------- 1 | flickr->request( 19 | 'flickr.people.findByEmail', 20 | ['find_email' => $findEmail] 21 | ); 22 | return isset($response['user']) ? $response['user'] : false; 23 | } 24 | 25 | /** 26 | * Return a user's NSID, given their username. 27 | * 28 | * This method does not require authentication. 29 | * 30 | * @link https://www.flickr.com/services/api/flickr.people.findByUsername.html 31 | * @param string $username The username of the user to lookup. 32 | * @return string|bool 33 | */ 34 | public function findByUsername($username) 35 | { 36 | $response = $this->flickr->request( 37 | 'flickr.people.findByUsername', 38 | ['username' => $username] 39 | ); 40 | return isset($response['user']) ? $response['user'] : false; 41 | } 42 | 43 | /** 44 | * Returns the list of groups a user is a member of. 45 | * 46 | * This method requires authentication. 47 | * 48 | * @link https://www.flickr.com/services/api/flickr.people.getGroups.html 49 | * @param string $userId The NSID of the user to fetch groups for. 50 | * @param string $extras A comma-delimited list of extra information to fetch for 51 | * each returned record. Currently supported fields are: privacy, 52 | * throttle, restrictions 53 | * @return 54 | */ 55 | public function getGroups($userId, $extras = null) 56 | { 57 | $params = [ 58 | 'user_id' => $userId, 59 | 'extras' => $extras 60 | ]; 61 | return $this->flickr->request('flickr.people.getGroups', $params); 62 | } 63 | 64 | /** 65 | * Get information about a user. 66 | * 67 | * This method does not require authentication. 68 | * 69 | * @link https://www.flickr.com/services/api/flickr.people.getInfo.html 70 | * @param string $userId The NSID of the user to fetch information about. 71 | * @return 72 | */ 73 | public function getInfo($userId) 74 | { 75 | $params = [ 76 | 'user_id' => $userId 77 | ]; 78 | $response = $this->flickr->request('flickr.people.getInfo', $params); 79 | return isset($response['person']) ? $response['person'] : null; 80 | } 81 | 82 | /** 83 | * Returns the photo and video limits that apply to the calling user account. 84 | * 85 | * This method requires authentication. 86 | * 87 | * @link https://www.flickr.com/services/api/flickr.people.getLimits.html 88 | * 89 | * @return 90 | */ 91 | public function getLimits() 92 | { 93 | return $this->flickr->request('flickr.people.getLimits'); 94 | } 95 | 96 | /** 97 | * Return photos from the given user's photostream. 98 | * Only photos visible to the calling user will be returned. 99 | * This method must be authenticated; 100 | * to return public photos for a user, use self::getPublicPhotos(). 101 | * @link https://www.flickr.com/services/api/flickr.people.getPhotos.html 102 | * @param string $userId The NSID of the user who's photos to return. A value of 103 | * "me" will return the calling user's photos. 104 | * @param int $safeSearch Safe search setting: 1 for safe. 2 for moderate. 3 for 105 | * restricted. (Please note: Un-authed calls can only see Safe content.) 106 | * @param string $minUploadDate Minimum upload date. Photos with an upload date greater than or 107 | * equal to this value will be returned. The date should be in the form of a unix timestamp. 108 | * @param string $maxUploadDate Maximum upload date. Photos with an upload date less than or 109 | * equal to this value will be returned. The date should be in the form of a unix timestamp. 110 | * @param string $minTakenDate Minimum taken date. Photos with an taken date greater than or 111 | * equal to this value will be returned. The date should be in the form of a mysql datetime. 112 | * @param string $maxTakenDate Maximum taken date. Photos with an taken date less than or equal 113 | * to this value will be returned. The date should be in the form of a mysql datetime. 114 | * @param int $contentType Content Type setting: 115 | * 1 for photos only. 116 | * 2 for screenshots only. 117 | * 3 for 'other' only. 118 | * 4 for photos and screenshots. 119 | * 5 for screenshots and 'other'. 120 | * 6 for photos and 'other'. 121 | * 7 for photos, screenshots, and 'other' (all). 122 | * @param int $privacyFilter Return photos only matching a certain privacy level. This only 123 | * applies when making an authenticated call to view photos you own. Valid values are: 124 | * 1 public photos 125 | * 2 private photos visible to friends 126 | * 3 private photos visible to family 127 | * 4 private photos visible to friends & family 128 | * 5 completely private photos 129 | * @param string $extras A comma-delimited list of extra information to fetch for each 130 | * returned record. Currently supported fields are: description, license, date_upload, 131 | * date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, 132 | * o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, 133 | * url_l, url_o 134 | * @param int $perPage Number of photos to return per page. The maximum allowed value is 500. 135 | * @param int $page The page of results to return. 136 | * @return string[]|bool Photo information, or false if none. 137 | */ 138 | public function getPhotos( 139 | $userId = 'me', 140 | $safeSearch = null, 141 | $minUploadDate = null, 142 | $maxUploadDate = null, 143 | $minTakenDate = null, 144 | $maxTakenDate = null, 145 | $contentType = null, 146 | $privacyFilter = null, 147 | $extras = null, 148 | $perPage = 100, 149 | $page = 1 150 | ) { 151 | $params = [ 152 | 'user_id' => $userId, 153 | 'safe_search' => $safeSearch, 154 | 'min_upload_date' => $minUploadDate, 155 | 'max_upload_date' => $maxUploadDate, 156 | 'min_taken_date' => $minTakenDate, 157 | 'max_taken_date' => $maxTakenDate, 158 | 'content_type' => $contentType, 159 | 'privacy_filter' => $privacyFilter, 160 | 'extras' => $extras, 161 | 'per_page' => $perPage, 162 | 'page' => $page, 163 | ]; 164 | $photos = $this->flickr->request('flickr.people.getPhotos', $params); 165 | return isset($photos['photos']) ? $photos['photos'] : false; 166 | } 167 | 168 | /** 169 | * Returns a list of photos containing a particular Flickr member. 170 | * 171 | * This method does not require authentication. 172 | * 173 | * @link https://www.flickr.com/services/api/flickr.people.getPhotosOf.html 174 | * @param string $userId The NSID of the user you want to find photos of. A value 175 | * of "me" will search against photos of the calling user, for authenticated calls. 176 | * @param string $ownerId An NSID of a Flickr member. This will restrict the list 177 | * of photos to those taken by that member. 178 | * @param string $extras A comma-delimited list of extra information to fetch for 179 | * each returned record. Currently supported fields are: description, 180 | * license, date_upload, date_taken, 181 | * date_person_added, owner_name, 182 | * icon_server, original_format, 183 | * last_update, geo, tags, 184 | * machine_tags, o_dims, views, 185 | * media, path_alias, url_sq, 186 | * url_t, url_s, url_q, url_m, 187 | * url_n, url_z, url_c, url_l, 188 | * url_o 189 | * @param string $perPage Number of photos to return per page. If this argument is 190 | * omitted, it defaults to 100. The maximum allowed value is 500. 191 | * @param string $page The page of results to return. If this argument is omitted, 192 | * it defaults to 1. 193 | * @return 194 | */ 195 | public function getPhotosOf($userId, $ownerId = null, $extras = null, $perPage = null, $page = null) 196 | { 197 | $params = [ 198 | 'user_id' => $userId, 199 | 'owner_id' => $ownerId, 200 | 'extras' => $extras, 201 | 'per_page' => $perPage, 202 | 'page' => $page, 203 | ]; 204 | return $this->flickr->request('flickr.people.getPhotosOf', $params); 205 | } 206 | 207 | /** 208 | * Returns the list of public groups a user is a member of. 209 | * 210 | * This method does not require authentication. 211 | * 212 | * @link https://www.flickr.com/services/api/flickr.people.getPublicGroups.html 213 | * @param string $userId The NSID of the user to fetch groups for. 214 | * @param string $invitationOnly Include public groups that require an invitation or administrator 216 | * approval to join. 217 | * @return 218 | */ 219 | public function getPublicGroups($userId, $invitationOnly = null) 220 | { 221 | $params = [ 222 | 'user_id' => $userId, 223 | 'invitation_only' => $invitationOnly 224 | ]; 225 | return $this->flickr->request('flickr.people.getPublicGroups', $params); 226 | } 227 | 228 | /** 229 | * Get a list of public photos for the given user. 230 | * 231 | * This method does not require authentication. 232 | * 233 | * @link https://www.flickr.com/services/api/flickr.people.getPublicPhotos.html 234 | * @param string $userId The NSID of the user who's photos to return. 235 | * @param string $safeSearch Safe search setting: (Please note: Un-authed 237 | * calls can only see Safe content.) 238 | * @param string $extras A comma-delimited list of extra information to fetch for 239 | * each returned record. Currently supported fields are: description, 240 | * license, date_upload, date_taken, 241 | * owner_name, icon_server, original_format, 242 | * last_update, geo, tags, 243 | * machine_tags, o_dims, views, 244 | * media, path_alias, url_sq, 245 | * url_t, url_s, url_q, url_m, 246 | * url_n, url_z, url_c, url_l, 247 | * url_o 248 | * @param string $perPage Number of photos to return per page. If this argument is 249 | * omitted, it defaults to 100. The maximum allowed value is 500. 250 | * @param string $page The page of results to return. If this argument is omitted, 251 | * it defaults to 1. 252 | * @return 253 | */ 254 | public function getPublicPhotos($userId, $safeSearch = null, $extras = null, $perPage = null, $page = null) 255 | { 256 | $params = [ 257 | 'user_id' => $userId, 258 | 'safe_search' => $safeSearch, 259 | 'extras' => $extras, 260 | 'per_page' => $perPage, 261 | 'page' => $page 262 | ]; 263 | return $this->flickr->request('flickr.people.getPublicPhotos', $params); 264 | } 265 | 266 | /** 267 | * Returns information for the calling user related to photo uploads. 268 | * 269 | * This method requires authentication. 270 | * 271 | * @link https://www.flickr.com/services/api/flickr.people.getUploadStatus.html 272 | * 273 | * @return 274 | */ 275 | public function getUploadStatus() 276 | { 277 | return $this->flickr->request('flickr.people.getUploadStatus'); 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /src/PhotosetsApi.php: -------------------------------------------------------------------------------- 1 | $photosetId, 21 | 'photo_id' => $photoId, 22 | ]; 23 | $response = $this->flickr->request('flickr.photosets.addPhoto', $args, true); 24 | return (bool)$response; 25 | } 26 | 27 | /** 28 | * Create a new photoset for the calling user. 29 | * This method requires authentication with 'write' permission. 30 | * New photosets are automatically put first in the photoset ordering for the user. 31 | * @see PhotosetsApi::orderSets() if you don't want the new set to appear first on the user's 32 | * photoset list. 33 | * @link https://www.flickr.com/services/api/flickr.photosets.create.html 34 | * @param string $title A title for the photoset. 35 | * @param string $description A description of the photoset. May contain limited HTML. 36 | * @param int $primaryPhotoId The ID of the photo to represent this set. The photo must belong 37 | * to the calling user. 38 | * @return bool|mixed[] 39 | */ 40 | public function create($title, $description, $primaryPhotoId) 41 | { 42 | $args = [ 43 | 'title' => $title, 44 | 'primary_photo_id' => $primaryPhotoId, 45 | 'description' => $description, 46 | ]; 47 | $response = $this->flickr->request('flickr.photosets.create', $args, true); 48 | return isset($response['photoset']) ? $response['photoset'] : false; 49 | } 50 | 51 | /** 52 | * Delete a photoset. This method requires authentication with 'write' permission. 53 | * @link https://www.flickr.com/services/api/flickr.photosets.delete.html 54 | * @param int $photosetId The id of the photoset to delete. It must be owned by the calling user. 55 | * @return bool 56 | */ 57 | public function delete($photosetId) 58 | { 59 | $args = ['photoset_id' => $photosetId]; 60 | return (bool)$this->flickr->request('flickr.photosets.delete', $args, true); 61 | } 62 | 63 | /** 64 | * Modify the meta-data for a photoset. 65 | * 66 | * This method requires authentication. 67 | * 68 | * @link https://www.flickr.com/services/api/flickr.photosets.editMeta.html 69 | * @param int $photosetId The ID of the photoset to modify. 70 | * @param string $title The new title for the photoset. 71 | * @param string|null $description A description of the photoset. May contain limited HTML. 72 | * @return bool 73 | */ 74 | public function editMeta($photosetId, $title, $description = null) 75 | { 76 | $args = [ 77 | 'photoset_id' => $photosetId, 78 | 'title' => $title, 79 | 'description' => $description, 80 | ]; 81 | return (bool)$this->flickr->request('flickr.photosets.editMeta', $args, true); 82 | } 83 | 84 | /** 85 | * Modify the photos in a photoset. Use this method to add, remove and re-order photos. 86 | * This method requires authentication. 87 | * @link https://www.flickr.com/services/api/flickr.photosets.editPhotos.html 88 | * @param int $photosetId The ID of the photoset to modify. The photoset must belong to the 89 | * calling user. 90 | * @param int $primaryPhotoId The ID of the photo to use as the 'primary' photo for the set. 91 | * This ID must also be passed along in $photoIds parameter. 92 | * @param string|string[] $photoIds An array or comma-delimited list of photo IDs to include in 93 | * the set. They will appear in the set in the order sent. This list must contain the primary 94 | * photo ID. All photos must belong to the owner of the set. This list of photos replaces the 95 | * existing list. Call flickr.photosets.addPhoto to append a photo to a set. 96 | * @return bool 97 | */ 98 | public function editPhotos($photosetId, $primaryPhotoId, $photoIds) 99 | { 100 | if (is_array($photoIds)) { 101 | $photoIds = join(',', $photoIds); 102 | } 103 | $args = [ 104 | 'photoset_id' => $photosetId, 105 | 'primary_photo_id' => $primaryPhotoId, 106 | 'photo_ids' => $photoIds 107 | ]; 108 | return (bool)$this->flickr->request('flickr.photosets.editPhotos', $args, true); 109 | } 110 | 111 | /** 112 | * Returns next and previous photos for a photo in a set. 113 | * 114 | * This method does not require authentication. 115 | * 116 | * @link https://www.flickr.com/services/api/flickr.photosets.getContext.html 117 | * @param int $photoId The ID of the photo to fetch the context for. 118 | * @param int $photosetId The ID of the photoset for which to fetch the photo's context. 119 | * @return mixed[] Array with 'prevphoto' and 'nextphoto' keys. 120 | */ 121 | public function getContext($photoId, $photosetId) 122 | { 123 | $args = [ 124 | 'photo_id' => $photoId, 125 | 'photoset_id' => $photosetId, 126 | ]; 127 | return $this->flickr->request('flickr.photosets.getContext', $args); 128 | } 129 | 130 | /** 131 | * Gets information about a photoset. 132 | * 133 | * This method does not require authentication. 134 | * 135 | * @link https://www.flickr.com/services/api/flickr.photosets.getInfo.html 136 | * @param int $photosetId The ID of the photoset to fetch information for. 137 | * @param string $userId The ID of the owner of the set passed in $photosetId. 138 | * @return mixed[]|bool 139 | */ 140 | public function getInfo($photosetId, $userId) 141 | { 142 | $args = [ 143 | 'photoset_id' => $photosetId, 144 | 'user_id' => $userId, 145 | ]; 146 | $response = $this->flickr->request('flickr.photosets.getInfo', $args); 147 | return isset($response['photoset']) ? $response['photoset'] : false; 148 | } 149 | 150 | /** 151 | * Returns the photosets belonging to the specified user. 152 | * 153 | * This method does not require authentication. 154 | * 155 | * @link https://www.flickr.com/services/api/flickr.photosets.getList.html 156 | * @param string $userId The NSID of the user to get a photoset list for. If none is 157 | * specified, the calling user is assumed. 158 | * @param int $page The page of results to get. Currently, if this is not provided, all sets are 159 | * returned, but this behaviour may change in future. 160 | * @param int $perPage The number of sets to get per page. If paging is enabled, the maximum 161 | * number of sets per page is 500. 162 | * @param string $primaryPhotoExtras A comma-delimited list of extra information to fetch for 163 | * the primary photo. Currently supported fields are: license, date_upload, date_taken, 164 | * owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, 165 | * views, media, path_alias, url_sq, url_t, url_s, url_m, url_o 166 | * @param string $photoIds A comma-separated list of photo ids. If specified, each returned set 167 | * will include a list of these photo IDs that are present in the set as 168 | * "has_requested_photos". 169 | * @param string $sortGroups A comma-separated list of groups used to sort the output sets. If has_photo is present, 170 | * any of the calling user's galleries containing photos referred to in photo_ids will be returned before other 171 | * galleries. The order of the sort_groups will dictate the order that the groups are returned in. Only available if 172 | * continuation is used. The resulting output will include a "sort_group" parameter indicating the sort_group that 173 | * each set is part of, or null if not applicable. 174 | * @return mixed[]|bool 175 | */ 176 | public function getList( 177 | $userId = null, 178 | $page = null, 179 | $perPage = null, 180 | $primaryPhotoExtras = null, 181 | $photoIds = null, 182 | $sortGroups = null 183 | ) { 184 | $args = [ 185 | 'user_id' => $userId, 186 | 'page' => $page, 187 | 'per_page' => $perPage, 188 | 'primary_photo_extras' => $primaryPhotoExtras, 189 | 'photo_ids' => $photoIds, 190 | 'sort_groups' => $sortGroups, 191 | ]; 192 | $response = $this->flickr->request('flickr.photosets.getList', $args); 193 | return isset($response['photosets']) ? $response['photosets'] : false; 194 | } 195 | 196 | /** 197 | * Get the list of photos in a set. 198 | * 199 | * This method does not require authentication. 200 | * 201 | * @link https://www.flickr.com/services/api/flickr.photosets.getPhotos.html 202 | * @param int $photosetId The photoset ID. 203 | * @param string $userId The owner of the photo set. 204 | * @param string|string[] $extras Extra information to fetch for each photo. Comma-delimited string or array of 205 | * strings. Possible values: license, date_upload, date_taken, owner_name, icon_server, original_format, 206 | * last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, and url_o. 207 | * @param int $perPage The number of results per page. Default and maximum are 500. 208 | * @param int $page Which page of results to return. 209 | * @param int $privacyFilter Return photos matching one of the following privacy levels: 210 | * 1 public photos; 211 | * 2 private photos visible to friends; 212 | * 3 private photos visible to family; 213 | * 4 private photos visible to friends & family; 214 | * 5 completely private photos. 215 | * @param string $media Filter results by media type. One of 'all', 'photos', or 'videos'. 216 | * @return array[]|bool 217 | */ 218 | public function getPhotos( 219 | $photosetId, 220 | $userId = null, 221 | $extras = null, 222 | $perPage = null, 223 | $page = null, 224 | $privacyFilter = null, 225 | $media = null 226 | ) { 227 | if (is_array($extras)) { 228 | $extras = join(',', $extras); 229 | } 230 | $args = [ 231 | 'photoset_id' => $photosetId, 232 | 'user_id' => $userId, 233 | 'extras' => $extras, 234 | 'per_page' => $perPage, 235 | 'page' => $page, 236 | 'privacy_filter' => $privacyFilter, 237 | 'media' => $media, 238 | ]; 239 | $response = $this->flickr->request('flickr.photosets.getPhotos', $args); 240 | return isset($response['photoset']) ? $response['photoset'] : false; 241 | } 242 | 243 | /** 244 | * Set the order of photosets for the calling user. 245 | * 246 | * This method requires authentication. 247 | * 248 | * @link https://www.flickr.com/services/api/flickr.photosets.orderSets.html 249 | * @param $photosetIds string|string[] An array or comma-delimited list of photoset IDs, ordered with the set to 250 | * show first, first in the list. Any set IDs not given in the list will be set to appear at the end of the list, 251 | * ordered by their IDs. 252 | * @return bool 253 | */ 254 | public function orderSets($photosetIds) 255 | { 256 | if (is_array($photosetIds)) { 257 | $photosetIds = implode(",", $photosetIds); 258 | } 259 | $response = $this->flickr->request("flickr.photosets.orderSets", ["photoset_ids" => $photosetIds], true); 260 | return isset($response['stat']) && $response['stat'] === 'ok'; 261 | } 262 | 263 | /** 264 | * Remove a photo from a photoset. 265 | * 266 | * This method requires authentication. 267 | * 268 | * @link https://www.flickr.com/services/api/flickr.photosets.removePhoto.html 269 | * @param $photosetId string The ID of the photoset to remove a photo from. 270 | * @param $photoId string The ID of the photo to remove from the set. 271 | * @return bool 272 | */ 273 | public function removePhoto($photosetId, $photoId) 274 | { 275 | $params = ["photoset_id" => $photosetId, "photo_id" => $photoId]; 276 | $response = $this->flickr->request("flickr.photosets.removePhoto", $params, true); 277 | return isset($response['stat']) && $response['stat'] === 'ok'; 278 | } 279 | 280 | /** 281 | * Remove multiple photos from a photoset. 282 | * 283 | * This method requires authentication. 284 | * 285 | * @link https://www.flickr.com/services/api/flickr.photosets.removePhotos.html 286 | * @param $photosetId string The ID of the photoset to remove photos from. 287 | * @param $photoIds string|string[] Array or comma-delimited list of photo IDs to remove from the photoset. 288 | * @return bool 289 | */ 290 | public function removePhotos($photosetId, $photoIds) 291 | { 292 | if (is_array($photoIds)) { 293 | $photoIds = implode(",", $photoIds); 294 | } 295 | $params = ['photoset_id' => $photosetId, 'photo_ids' => $photoIds]; 296 | $response = $this->flickr->request('flickr.photosets.removePhotos', $params, true); 297 | return isset($response['stat']) && $response['stat'] === 'ok'; 298 | } 299 | 300 | /** 301 | * Reorder some or all of the photos in a set. 302 | * This method requires authentication. 303 | * @link https://www.flickr.com/services/api/flickr.photosets.reorderPhotos.html 304 | * @param $photosetId string The ID of the photoset to reorder. The photoset must belong to the calling user. 305 | * @param $photoIds string|string[] Ordered, comma-delimited list or array of photo IDs. Photos that are not in the 306 | * list will keep their original order. 307 | * @return bool 308 | */ 309 | public function reorderPhotos($photosetId, $photoIds) 310 | { 311 | if (is_array($photoIds)) { 312 | $photoIds = implode(",", $photoIds); 313 | } 314 | $params = ['photoset_id' => $photosetId, 'photo_ids' => $photoIds]; 315 | $response = $this->flickr->request('flickr.photosets.reorderPhotos', $params, true); 316 | return isset($response['stat']) && $response['stat'] === 'ok'; 317 | } 318 | 319 | /** 320 | * Set the primary photo of a photoset. 321 | * This method requires authentication. 322 | * @link https://www.flickr.com/services/api/flickr.photosets.setPrimaryPhoto.html 323 | * @param $photosetId string The ID of the photoset to set primary photo to. 324 | * @param $photoId string The ID of the photo to set as primary. 325 | * @return bool 326 | */ 327 | public function setPrimaryPhoto($photosetId, $photoId) 328 | { 329 | $response = $this->flickr->request( 330 | 'flickr.photosets.setPrimaryPhoto', 331 | ['photoset_id' => $photosetId, 'photo_id' => $photoId], 332 | true 333 | ); 334 | return isset($response['stat']) && $response['stat'] === 'ok'; 335 | } 336 | } 337 | --------------------------------------------------------------------------------