简体   繁体   English

Flickr API 返回的场值无效

[英]Invalid farm value returned by Flickr API

I have this app that searches tags on flickr and returns results.我有这个应用程序可以在 flickr 上搜索标签并返回结果。

The results are displayed on an infinite collection view.结果显示在无限集合视图上。

Results are returned 100 at a time.结果一次返回 100 个。

I start to scroll and reach the bottom of the scroll view.我开始滚动并到达滚动视图的底部。 Another 100 elements are requested from Flickr and the thing works fine.从 Flickr 请求另外 100 个元素,并且一切正常。

If I continue to scroll down for a while, after entering the 5th page (elements 400-499), I start to get this error:如果我继续向下滚动一段时间,进入第5页(元素400-499)后,我开始收到此错误:

NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D87E6C4C-B8CB-46D1-B891-3E7CDF35ABDF>.<1>"
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg, NSErrorFailingURLKey=https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg, _kCFStreamErrorDomainKey=12}

Look at the url.看网址。

https://farm0.static.flickr.com/0/50255650726_a4c7ba2298.jpg

if you change farm0 to farm1 the image loads.如果您将farm0更改为farm0farm1加载图像。

I am creating the image download url like this:我正在创建这样的图像下载网址:

func makeDownloadURL() -> URL{
  let path = "https://farm\(farm).static.flickr.com/\(server)/\(id)_\(secret).jpg"
  return URL(string: path)!
}

The strange part is that if I continue to scroll past the missing images, at some point, valid images start to fill the collection view.奇怪的是,如果我继续滚动过去丢失的图像,在某些时候,有效图像开始填充集合视图。 Then, the problem again, valid images again, and so one.然后,问题又来了,又是有效图像,依此类推。

I am using this to build the search URL我正在使用它来构建搜索 URL

  func makeSearchURLComponents(searchString:String) -> URLComponents? {
    var components = URLComponents()
    components.scheme = "https"
    components.host = "api.flickr.com"
    components.path = "/services/rest"

    let queryMethod       = URLQueryItem(name: "method", value: "flickr.photos.search")
    let queryAPI          = URLQueryItem(name: "api_key", value: flickrAPI)
    let queryFormat       = URLQueryItem(name: "format", value: retrieveFormat)
    let querySafeSearch   = URLQueryItem(name: "safe_search", value: SafeSearch.Safe.rawValue)
    let querySearchString = URLQueryItem(name: "tags", value: searchString)
    let queryPageNumber   = URLQueryItem(name: "page", value: String(pageNumber))
    let querycallBack     = URLQueryItem(name: "nojsoncallback", value: "1")
    components.queryItems = [queryMethod, queryAPI, queryFormat, querySafeSearch, querySearchString, queryPageNumber, querycallBack]

    return components
  }

why is that.这是为什么。

It appears to be a flickr problem.这似乎是一个 flickr 问题。

The solution is to correct farm to 1 when it is zero.解决方案是在农场为零时将其校正为 1。

let correctedFarm = farm == 0 ? 1 : farm

It is a hack to circumvent their bug.绕过他们的错误是一种黑客行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM