Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A CATastrophic bug: Flickr API returns only kittens instead of birds #270

Open
jeffsikes opened this issue Jan 9, 2025 · 1 comment
Open

Comments

@jeffsikes
Copy link

Describe the bug
When the flickr API call sends a request, the returned response is full of cats and kittens.

Side note: This was the most entertaining bug hunt in my entire lifetime of coding. Of all the types of cross platform bugs to see - a bird identification app returning flickr cat photos by mistake - is just purrrfectly ironic. (Sorry, not sorry).

To Reproduce
Steps to reproduce the behavior:

  1. Enter your Filckr API into the configuration file
  2. Restart your system
  3. Go to "Best Recordings" in Birdnet
  4. Choose a species
  5. Scroll down below the audio file.
  6. See kittens.

Expected behavior
I expect to see birds. 😸

Screenshots
image

Additional context
I migrated from this other fork, following the instructions for the migration. I noticed this issue right afterwards. If I revert to my backup from prior to the migration, birds appear from the flickr call as expected.

https://github.com/mcguirepr89/BirdNET-Pi

Your build
Rasberry Pi Model 4B
Version: Main branch (commit e3eb094)

Code or log snippets

function get_com_en_name($sci_name) {

$engame is a value generated from this function get_com_en_name, which relies on passing in a scientific name, which is being passed in as empty.

So null is returned. This is a separate issue that I need to review (why is scientific name always empty?). It may be related to the migration I did and file permission issues.

But on with the kitten conundrum.

The issue is with the line below. The text parameter is being created with double quotes with nothing in between them, which then gets URL encoded.

$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace(' ', '%20', $engname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];

This generates a call to the API that looks like this:

https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=REDACTED&text=%22%22&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1

Note about Flickr API behavior:
Interestingly, this appears to be undocumented behavior in the Flickr API where sending text="" (URL encoded as %22%22) seems to trigger a default response or possible easter egg that returns kitten photos. When the quotes are removed and just text= is sent, the API returns random photos as expected. This behavior isn't documented in Flickr's API documentation, making this bug both amusing and confusing.

I searched Flickr's API documentation and it may be an easter egg - there seem to be some cat people working there!

Flickr API Posts Tagged with Kittens

Change the line to:

$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".str_replace(' ', '%20', $engname)."&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"]; 

And you now just have random photos, which is a debatable improvement to kittens.

@Nachtzuster
Copy link
Owner

Quite entertaining indeed, I love that Easter egg.

I'm not sure if I follow though... did you figure out in the end why you got an empty $sci_name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants