PHPackages                             carlos-mg89/phpflickr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. carlos-mg89/phpflickr

ActiveLibrary

carlos-mg89/phpflickr
=====================

A PHP wrapper for the Flickr API, including Oauth.

4.15.2(3y ago)023GPL-3.0-or-laterPHPPHP ^8.0CI failing

Since Oct 17Pushed 3y agoCompare

[ Source](https://github.com/carlos-mg89/phpflickr)[ Packagist](https://packagist.org/packages/carlos-mg89/phpflickr)[ RSS](/packages/carlos-mg89-phpflickr/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (6)Versions (31)Used By (0)

PhpFlickr
=========

[](#phpflickr)

A PHP wrapper for the Flickr API.

[![Packagist](https://camo.githubusercontent.com/a2502e6ebef711330e5ed50b57541850229dc6c2e652cf9e25d0faf5f9ceead7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d77696c736f6e2f706870666c69636b722e737667)](https://packagist.org/packages/samwilson/phpflickr)

[![Build status](https://github.com/samwilson/phpflickr/workflows/CI/badge.svg)](https://github.com/samwilson/phpflickr/actions/workflows/ci.yml)

Table of contents:

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Authentication](#authentication)
- [Making authenticated requests](#making-authenticated-requests)
- [Caching](#caching)
- [Proxy server](#proxy-server)
- [Uploading](#uploading)
- [Kudos](#kudos)

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org/):

```
composer require samwilson/phpflickr

```

Usage
-----

[](#usage)

Once you've included Composer's autoloader, create a PhpFlickr object. For example:

```
require_once 'vendor/autoload.php';
$flickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret);
```

The constructor takes two arguments:

1. `$apiKey` — This is the API key given to you by Flickr when you [register an app](https://www.flickr.com/services/api/keys/).
2. `$secret` — The API secret is optional because it is only required to make authenticated requests ([see below](#making-authenticated-requests)). It is given to you along with your API key when you register an app.

All of the API methods have been implemented in phpFlickr. You can see a full list and documentation here:

To call a method, remove the "flickr." part of the name and replace any periods with underscores. For example, instead of flickr.photos.search, you would call $f-&gt;photos\_search() or instead of flickr.photos.licenses.getInfo, you would call $f-&gt;photos\_licenses\_getInfo() (yes, it is case sensitive).

All functions have their arguments implemented in the list order on their documentation page (a link to which is included with each method in the phpFlickr clasS). The only exceptions to this are photos\_search(), photos\_getWithoutGeodata() and photos\_getWithoutGeodata() which have so many optional arguments that it's easier for everyone if you just have to pass an associative array of arguments. See the comment in the photos\_search() definition in phpFlickr.php for more information.

Examples
--------

[](#examples)

There are a few example files in the `examples/` directory. To use these, first copy `examples/config.dist.php` to `examples/config.php`and run `php examples/get_auth_token.php` to get the access token. Add this access token to your `examples/config.php`and then you can run any of the examples that require authentication (note that not all of them do).

Authentication
--------------

[](#authentication)

There is only one user authentication method available to the API, and that is OAuth 1.0. You only need to use this if you're performing operations that require it, such as uploading or accessing private photos.

This authentication method is somewhat complex, but is secure and allows your users to feel a little safer authenticating to your application. You don't have to ask for their username and password.

☛ *Read more about the [Flickr Authentication API](https://www.flickr.com/services/api/auth.oauth.html).*

We know how difficult this API looks at first glance, so we've tried to make it as transparent as possible for users of phpFlickr. We'll go through all of the steps you'll need to do to use this.

To have end users authenticate their accounts:

1. Create an object in which to temporarily store the authentication token, and give it to PhpFlickr. This must be an implementation of TokenStorageInterface, and will usually be of type `Session` (for browser-based workflows) or `Memory` (for command-line workflows) — or you can create your own implementation.

    ```
    $storage = new \OAuth\Common\Storage\Memory();
    $flickr->setOauthStorage($storage);
    ```
2. Send your user to a Flickr URL (by redirecting them, or just telling them to click a link), where they'll confirm that they want your application to have the permission you specify (which is either `read`, `write`, or `delete`).

    ```
    $perm = 'read';
    $url = $flickr->getAuthUrl($perm, $callbackUrl);
    ```
3. Once the user has authorized your application, they'll either be redirected back to a URL on your site (that you specified as the callback URL above) or be given a nine-digit code that they'll need to copy and paste into your application.

    1. For the browser-based workflow, your callback URL will now have two new query-string parameters: `oauth_token` and `oauth_verifier`.
    2. For CLI workflow, you'll need to strip anything other than digits from the string that the user gives you (e.g. leading and trailing spaces, and the hyphens in the code).
4. You can now request the final 'access token':

    1. For the browser-based workflow: ```
        $accessToken = $flickr->retrieveAccessToken($_GET['oauth_verifier'], $_GET['oauth_token']);
        ```
    2. For the CLI workflow, it's much the same, but because you've still got access to the request token you can leave it out when you run this request: ```
        $verifier = '';
        $accessToken = $flickr->retrieveAccessToken($verifier);
        ```
5. Now you can save the two string parts of the access token (which you can get via the `$accessToken->getAccessToken()` and `$accessToken->getAccessTokenSecret()` methods) and use this for future requests. The access token doesn't expire, and must be stored securely (the details of doing that are outside the scope of PhpFlickr).

Making authenticated requests
-----------------------------

[](#making-authenticated-requests)

Once you have an access token (see [above](#authentication)), you can store it somewhere secure and use it to make authenticated requests at a later time. To do this, first create a storage object (again, as for the initial authentication process, you can choose between different storage types, but for many situations the in-memory storage is sufficient), and then store your access token in that object:

```
// Create storage.
$storage = new \OAuth\Common\Storage\Memory();
// Create the access token from the strings you acquired before.
$token = new \OAuth\OAuth1\Token\StdOAuth1Token();
$token->setAccessToken($accessToken);
$token->setAccessTokenSecret($accessTokenSecret);
// Add the token to the storage.
$storage->storeAccessToken('Flickr', $token);
```

Now, you can pass the storage into PhpFlickr, and start making requests:

```
$flickr->setOauthStorage($storage);
$recent = $phpFlickr->photos_getContactsPhotos();
```

See the [Usage section](#usage) above for more details on the request methods, and the `examples/recent_photos.php` file for a working example.

Caching
-------

[](#caching)

PhpFlickr can be used with any PSR-6 compatible cache, such as [symfony/cache](https://packagist.org/packages/symfony/cache)or [tedivm/stash](https://packagist.org/packages/tedivm/stash).

To enable caching, pass a configured cache object to `PhpFlickr::setCache($cacheItemPool)`.

All requests are cached for the same time duration, which by default is 10 minutes. This can be changed with the `PhpFlickr::setCacheDefaultExpiry()`.

Uploading
---------

[](#uploading)

### Uploading new photos

[](#uploading-new-photos)

Uploading is pretty simple. Aside from being authenticated (see the [Authentication](#Authentication) section above) the very minimum that you'll have to pass is a path to an image file. You can upload a file as follows:

```
$flickr->uploader()->upload('/path/to/photo.jpg');
```

The other upload parameters are documented in the method's docblock. One useful one is the `$async` flag, which permits *asyncronous* uploading, which means that, rather than uploading the file immediately and before returning, a 'ticket ID' is returned, with which you can subsequently fetch the upload's status. You can read more about asynchronous uploading in [Flickr's API documentation](https://www.flickr.com/services/api/upload.async.html).

### Replacing existing photos

[](#replacing-existing-photos)

You can also upload a photo as a replacement to an existing photo.

```
$flickr->uploader()->replace('/path/to/photo.jpg', 44333812150);
```

This method doesn't allow for setting any photo metadata, but you can do the replacement asynchronously (in which case a 'ticket ID' will be returned).

Proxy server
------------

[](#proxy-server)

PhpFlickr can be used with a proxy server or any service that matches Flickr's API (such as [23 Photo Sharing](http://www.23hq.com)). To use this feature, pass the proxy server's base URL after instantiating a PhpFlickr object. For example:

```
$flickr->setProxyBaseUrl('http://localhost:8181/flickr');
```

After that, all requests will be automatically made through your proxy server.

One example of configuring such a proxy service, for the Apache webserver, is as follows:

```
ProxyRequests Off
SSLProxyEngine on
ProxyPass /flickr https://api.flickr.com/services
ProxyPassReverse /flickr https://api.flickr.com/services

```

Kudos
-----

[](#kudos)

This is a fork of Dan Coulter's original [phpFlickr](https://github.com/dan-coulter/phpflickr)library, maintained by Sam Wilson. All the hard work was done by Dan!

Thanks also is greatly due to the many other [contributors](https://github.com/samwilson/phpflickr/graphs/contributors).

The [Agateware\_Example.JPG](https://commons.wikimedia.org/wiki/File:Agateware_Example.JPG)used for the upload examples is [CC-BY-SA](https://creativecommons.org/licenses/by-sa/4.0)by User:Anonymouse512, via Wikimedia Commons.

###  Health Score

33

—

LowBetter than 76% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 61.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~166 days

Total

28

Last Release

1383d ago

PHP version history (2 changes)4.0.0PHP &gt;=5.6

4.15.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8786299c65265ae26a7ded6132169b83642352b772faf17ecf0aa6a25b1b6f15?d=identicon)[carlos-mg89](/maintainers/carlos-mg89)

---

Top Contributors

[![samwilson](https://avatars.githubusercontent.com/u/213655?v=4)](https://github.com/samwilson "samwilson (79 commits)")[![carlos-mg89](https://avatars.githubusercontent.com/u/19690868?v=4)](https://github.com/carlos-mg89 "carlos-mg89 (20 commits)")[![dan-coulter](https://avatars.githubusercontent.com/u/6157344?v=4)](https://github.com/dan-coulter "dan-coulter (14 commits)")[![mikeMTOL](https://avatars.githubusercontent.com/u/7033932?v=4)](https://github.com/mikeMTOL "mikeMTOL (3 commits)")[![alerque](https://avatars.githubusercontent.com/u/173595?v=4)](https://github.com/alerque "alerque (2 commits)")[![mistic100](https://avatars.githubusercontent.com/u/41597?v=4)](https://github.com/mistic100 "mistic100 (2 commits)")[![fbianco](https://avatars.githubusercontent.com/u/1819057?v=4)](https://github.com/fbianco "fbianco (1 commits)")[![calebdre](https://avatars.githubusercontent.com/u/3318929?v=4)](https://github.com/calebdre "calebdre (1 commits)")[![vojtasvoboda](https://avatars.githubusercontent.com/u/374917?v=4)](https://github.com/vojtasvoboda "vojtasvoboda (1 commits)")[![nogorilla](https://avatars.githubusercontent.com/u/1786677?v=4)](https://github.com/nogorilla "nogorilla (1 commits)")[![benjaminchodroff](https://avatars.githubusercontent.com/u/4411206?v=4)](https://github.com/benjaminchodroff "benjaminchodroff (1 commits)")[![scotthorn](https://avatars.githubusercontent.com/u/1498266?v=4)](https://github.com/scotthorn "scotthorn (1 commits)")[![sillygwailo](https://avatars.githubusercontent.com/u/54067?v=4)](https://github.com/sillygwailo "sillygwailo (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/carlos-mg89-phpflickr/health.svg)

```
[![Health](https://phpackages.com/badges/carlos-mg89-phpflickr/health.svg)](https://phpackages.com/packages/carlos-mg89-phpflickr)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k570.0M5.0k](/packages/doctrine-dbal)[doctrine/orm

Object-Relational-Mapper for PHP

10.2k280.5M5.7k](/packages/doctrine-orm)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k341.5M2.2k](/packages/symfony-cache)[doctrine/persistence

The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.

4.1k280.8M675](/packages/doctrine-persistence)[gedmo/doctrine-extensions

Doctrine behavioral extensions

4.1k116.9M338](/packages/gedmo-doctrine-extensions)[symfony/cache-contracts

Generic abstractions related to caching

2.4k301.9M164](/packages/symfony-cache-contracts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
