簡體   English   中英

Flickr API 返回的場值無效

[英]Invalid farm value returned by Flickr API

我有這個應用程序可以在 flickr 上搜索標簽並返回結果。

結果顯示在無限集合視圖上。

結果一次返回 100 個。

我開始滾動並到達滾動視圖的底部。 從 Flickr 請求另外 100 個元素,並且一切正常。

如果我繼續向下滾動一段時間,進入第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}

看網址。

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

如果您將farm0更改為farm0farm1加載圖像。

我正在創建這樣的圖像下載網址:

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

奇怪的是,如果我繼續滾動過去丟失的圖像,在某些時候,有效圖像開始填充集合視圖。 然后,問題又來了,又是有效圖像,依此類推。

我正在使用它來構建搜索 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
  }

這是為什么。

這似乎是一個 flickr 問題。

解決方案是在農場為零時將其校正為 1。

let correctedFarm = farm == 0 ? 1 : farm

繞過他們的錯誤是一種黑客行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM