PHP code example of jooservices / flickr

1. Go to this page and download the library: Download jooservices/flickr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jooservices / flickr example snippets


use JOOservices\Flickr\Config\FlickrConfig;
use JOOservices\Flickr\FlickrFactory;

$flickr = FlickrFactory::make(FlickrConfig::from([
    'apiKey' => $_ENV['FLICKR_API_KEY'],
    'apiSecret' => $_ENV['FLICKR_API_SECRET'],
    'callbackUrl' => $_ENV['FLICKR_CALLBACK_URL'] ?? null,
    'retryTimes' => 2,
]));

use JOOservices\Flickr\DTO\Photos\SearchPhotosData;

$response = $flickr->photos()->search(SearchPhotosData::from([
    'text' => 'sunset',
    'tags' => ['landscape'],
    'perPage' => 20,
]));

use JOOservices\Flickr\DTO\Common\PaginationOptionsData;

foreach ($flickr->photos()->searchPages(
    SearchPhotosData::from(['text' => 'sunset']),
    new PaginationOptionsData(maxPages: 3, perPage: 50),
) as $page) {
    // $page is ApiResponseData
}

$searchResult = $flickr->photos()->searchData(SearchPhotosData::from(['text' => 'sunset']));
$photo = $flickr->photos()->getInfoData('123456');
$person = $flickr->people()->getInfoData('12345678@N00');

use JOOservices\Flickr\Enums\PhotoSize;
use JOOservices\Flickr\Support\PhotoUrlBuilder;

$url = PhotoUrlBuilder::forPhoto($photo)->url(PhotoSize::Medium640);

$response = $flickr->raw()->call('flickr.photos.search', [
    'text' => 'cats',
    'per_page' => 10,
]);

$hotTags = $flickr->tags()->getHotList(['count' => 20]);

$recent = $flickr->photos()->getRecent([
    'per_page' => 20,
    'extras' => ['url_m', 'owner_name'],
]);

$favorite = $flickr->favorites()->add([
    'photo_id' => '123456',
]);

$location = $flickr->photosGeo()->getLocation([
    'photo_id' => '123456',
]);

use JOOservices\Flickr\Enums\AuthPermission;

$requestToken = $flickr->auth()->requestToken(AuthPermission::Write);
$authorizationUrl = $flickr->auth()->authorizationUrl($requestToken, AuthPermission::Write);

// Persist the request token secret between the redirect legs (e.g. in session storage).
$requestTokenSecret = $requestToken->oauthTokenSecret;

// After Flickr redirects back with oauth_token and oauth_verifier:
$accessToken = $flickr->auth()->accessToken($oauthToken, $oauthVerifier, $requestTokenSecret);
$flickr->tokens()->put($accessToken);

use JOOservices\Flickr\DTO\Upload\UploadPhotoData;
use JOOservices\Flickr\Enums\Privacy;

$result = $flickr->uploads()->upload(UploadPhotoData::from([
    'path' => '/tmp/photo.jpg',
    'title' => 'My photo',
    'tags' => ['php', 'flickr'],
    'privacy' => Privacy::Private,
    'async' => true,
]));

$ticketResponse = $flickr->uploads()->checkTickets([$result->ticketId]);

use JOOservices\Flickr\DTO\Upload\ReplacePhotoData;

$result = $flickr->uploads()->replace(ReplacePhotoData::from([
    'path' => '/tmp/new-photo.jpg',
    'photoId' => '123456',
    'async' => true,
]));

use JOOservices\Flickr\Cache\Psr16Cache;

$flickr = FlickrFactory::make(
    config: $config,
    cache: new Psr16Cache($psr16Cache),
);

use JOOservices\Flickr\Client\FakeFlickrTransport;

$transport = FakeFlickrTransport::new()->pushJson([
    'stat' => 'ok',
    'photos' => ['page' => 1, 'pages' => 1, 'perpage' => 1, 'total' => 0, 'photo' => []],
]);

$flickr = FlickrFactory::make(
    config: new FlickrConfig('test-key', 'test-secret'),
    transport: $transport,
);