English 中文(简体)
How to check if a flickr url is valid
原标题:
  • 时间:2009-11-24 13:12:53
  •  标签:
  • flickr

We need the user to be able to enter URLs in our media section . However since users can make mistakes in entering the URLs , we need to ensure that the URLs are valid flickr URLs . Valid URL eg : http://www.flickr.com/photos/53067560@N00/sets/72157606175084388/

Invalid URL eg : http://www.flickr.com/photos/53067560@N00/sets/12345/

Flickr offers API services , but I could not find one that would validate a URL .

最佳回答

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

You could also use regex to ensure that it matches the expected pattern, which would possibly cut down the amount of requests you would have to make.

问题回答

You could 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 ok. In all likelyhood good URLs will return 200 code.

I am pretty sure you can at least use `flickr.photos.getInfo to see if the photo in question exists. The rest of the URL can be validated according to the result received.

You can t check for every possible permutation of course but when it comes to photo id, I am pretty certain you can rely on Flickr API... or else, they would be in trouble themselves, no?

Of course, you can double-check by issuing an HTTP GET request on the URL and verify that the result HTTP code is something like 200 (or maybe something >=200 & <=300).





相关问题
POST to Page Returned By WebResponse

I am using WebRequest to POST to a signin page that redirects me to the page I really need to post to. How can I post to this page that I have been redirected to? Here is the Code: *****NEW STUFF****...

Adding a photo collection using the flickr API

Is it possible to create a photo collection using the flickr API? I haven t found any example code to achieve this, however you CAN do it on the flickr website, and i suppose flickr uses the API ...

how can I get yesterdays date in unix format in javascript?

I m self-learning the REST concept and am playing with the Flickr API. One of the parameters that Flickr requires is the min_upload_date, which is formatted in the Unix date format and looks like ...

How to check if a flickr url is valid

We need the user to be able to enter URLs in our media section . However since users can make mistakes in entering the URLs , we need to ensure that the URLs are valid flickr URLs . Valid URL eg : ...

How to set the number of photos in flickr

I am reading this page about Zend_Service_Flickr. However it does not say how to set up the number of photos showing. The following code returns 10 images. Zend_Loader::loadClass( ...

热门标签