Flickr API integration in Flutter with Dart

Daniel Kao
3 min readJul 23, 2019

Flickr used to be a cool photo service that gathered many talented photographers. I started uploading all my photos to it since 2005, and now I’ve uploaded more than 160k photos. With so many memories in Flickr, I would like to have an app to randomly show me my own photos in order to refresh good old memories.

There are many Flickr API Kits in different programming languages in Flickr official website; however, Dart is not one of them. I either need to implement the API wrapper by referencing its Web API document or find another solution on the internet.

Without luck, I couldn’t find useful Flickr related implementations for dart. I decided to wrap the Web APIs in dart by myself. But first of all, I need to deal with the authentication process. You can see the authentication process explained below.

Authentication difficulties

Flickr still uses OAuth version 1.0. It needs 3 API calls to complete the authentication process. Among the flow, a web page interaction is required for users to grant the access, and get the pin code to input into second API call.

It would take some effort to implement the OAuth1 signature generation, and appending related http query string parameters along with the APIs that needs authentication. Fortunately, someone already implemented the hard work for OAuth1 authentication. We only have to pass in necessary information related to Flickr in order to make it work.

By the way, remember to get your own developer API key and API secrete from Flickr.

oauth1 for OAuth authentication

By following the oauth1 package’s documentation you can initiate the flow like this and call the requestTemporaryCredentials(). It will return the Web url that you need to display to users.

url_launcher : for WebView

For displaying webview, I used url_launcher package. It’s very straightforward too.

The WebView to ask for user permission.
After getting user permission, it will show the pin code

After getting the pin-code from webview, A dialog will be displayed to ask user input the pin-code, and feed it into requestToken().

Create a dialog to get the pin code from user.

In the end, requestToken will successfully return an oauth1.Client object, that can be used to call other Flickr API.

Voila! The authentication is done! The rest part is pure dart and flutter implementation which can be easily built up based on sample codes on flutter web site.

That’s it! With one night effort, my app is running well in my android phone, and also in the iOS simulator too. :)

A simple grid view layout to show random page of photos from my own Flickr account

PS.

Now there’s a better way to get pin code! Please check my another article:

--

--

Daniel Kao

2023 年新書出版! Android 開源專案「真」實戰啟航:瀏覽器 App EinkBro 開發者帶你逐步從 UI 設計、UX 提升到多功能實現秘技全解析