How to validate flickr url

We need the user to be able to enter URLs in our multimedia section. However, since users may be mistaken in entering URLs, we need to make sure that the URLs are valid flickr URLs. Valid URL e.g .: http://www.flickr.com/photos/ 53067560 @ N00 / sets / 72157606175084388 /

Invalid url e.g .: http://www.flickr.com/photos/ 53067560 @ N00 / sets / 12345 /

Flickr offers API services, but I could not find one that will validate the URL.

+3
source share
3 answers

The easiest way is to make a HEAD HTTP request for the URL, which would mean that the URL is valid if it returns an HTTP 200 response code.

You can also use a regular expression to make sure that it matches the expected pattern, which could reduce the number of queries you would need to make.

+4
source

You can make an HTTP HEAD request to the URL and check the http response code. Any response code greater than or equal to 200 and less than 300 is approved. In all likelihood, good URLs will return 200 codes.

+1
source

, `flickr.photos.getInfo ', , . URL- .

You can't check every possible permutation, but when it comes to photo id, I'm pretty sure you can rely on the Flickr API ... otherwise they themselves will be in trouble, no?

Of course, you can double check by sending an HTTP GET request to the URL and make sure the HTTP result code is something like 200(or maybe something> = 200 and <= 300).

0
source

Source: https://habr.com/ru/post/1723777/


All Articles