The photo ID of the test image is 6766932173
I reverse lookedup the website's XHR requests to find that the API method was flickr.photos.getGroups. Note: no official documentation on this method is available on Flickr API page, but it works.
Code:
import requests
def get_photo_groups(api_key, photo_id, per_page=50):
url = "https://api.flickr.com/services/rest"
params = {
"method": "flickr.photos.getGroups",
"api_key": api_key,
"photo_id": photo_id,
"format": "json",
"nojsoncallback": "1",
"per_page": str(per_page)
}
response = requests.get(url, params=params)
groups = []
if response.status_code == 200:
data = response.json()
groups = data.get("groups", {}).get("group", [])
print("Total Groups:", len(groups))
else:
print("Error:", response.status_code)
return groups
# Set your API key here
api_key = "c798cd893a9097d9c34875e61217c6a0" #use it if you don't want to get a new one. Only active for the next 48 hours.
# Set the photo ID here
photo_id = "6766932173"
groups = get_photo_groups(api_key, photo_id)
for i, group in enumerate(groups, start=1):
print(f"\nGroup {i}:")
print("ID:", group.get("id"))
print("Title:", group.get("title"))
print("Member Count:", group.get("member_count"))
print("Pool Count:", group.get("pool_count"))
# Add any other details you want to print here
This should return 50 groups but it sometimes returns 25 and sometimes 36. The original number of groups to which the image belongs to is 69. What is the issue? Any suggestions on the code modifications?
I dont get the full list of 69 groups in which the image is present. They have something called continuation parameter. I tried using that but it still fails to get the full list of 69 groups.