Introduction to using FlickrAPI

This vignette provides a quick tour of the R package “FlickrAPI”. This package is maintained by Koki Ando.

Installation

# pak::pkg_install("koki25ando/FlickrAPI")
library(FlickrAPI)

Setting up a Flickr API key

# Set the API key for a single session
setFlickrAPIKey(api_key = "YOUR_API_KEY_HERE")

# Install the API key for future sessions
setFlickrAPIKey(api_key = "YOUR_API_KEY_HERE", install = TRUE)

# Overwrite an existing API key
setFlickrAPIKey(api_key = "YOUR_API_KEY_HERE", overwrite = TRUE)

Searching for Flickr photos

There are two functions for searching Flickr photos:

  • getPhotos()
  • getPhotoSearch()

getPhotos() allows you to get public photos for any Flickr user or all photos from the account associated with the Flickr API key.

# Search for photos uploaded by Koki Ando
getPhotos(user_id = "141696738@N08")

getPhotoSearch() supports a broader range of search options including:

  • User id
  • Tags
  • License
  • Bounding box (for photos with locations)
getPhotoSearch(tags = c("cats", "dogs"))
# Search for photos of cats and dogs in North Carolina
nc_bbox <- c(-84.32385, 33.88199, -75.45698, 36.58965)

getPhotoSearch(tags = c("cats", "dogs"), bbox = nc_bbox)

getPhotoSearch() returns 100 photos per page by default but this can be increased to 250 if using the bbox parameter searching by location or 500 otherwise. Additional pages can be accessed using the page parameter.

The extras parameter can be used to return additional information about the photos including “description”, “date_upload”, “date_taken”, “owner_name”, and urls for all available image sizes.

# Search for photos tagged "panda" in the area of Ueno Zoo, Tokyo, Japan
getPhotoSearch(
  tags = "panda",
  bbox = c(139.7682226529, 35.712627977, 139.7724605432, 35.7181464141),
  sort = "interestingness-desc",
  extras = c("geo", "tags")
)

Get data on Flickr photos

There are two functions for getting data about a specific Flickr photo:

  • getExif()
  • getPhotoInfo()

Get Flickr data for a photo

getPhotoInfo(photo_id = "51899696261", output = "url")

Get EXIF metadata for a photo

getExif(photo_id = "51872765082")