在 swift iOS 上无法从 foursquare api 获取图像

Can't get an image from foursquare api, on swift iOS

我正在为 swift (QuadratTouch) 使用 das quadrat foursquare sdk 一切正常,期待得到图像 他们在 JSON 中标记为 "prefix" 和 "suffix" 之类的 NSDictionary 和 UIImage 最后得到 nil

正在解析 JSON 并创建正常 url

let parameters = [Parameter.ll:"\(lat),\(long)", Parameter.limit:"35", Parameter.radius:"\(radius)", Parameter.intent:"browse"]
    let currentTask = session.venues.search(parameters) {
        (result) -> Void in
        var places = [Place]()
        if let response = result.response {
            if let venues =  response["venues"] as? NSArray {
                for venue in venues {
                    if let categories = venue["categories"] as? NSArray {
                       let categoryInfo = categories[0] as! NSDictionary
                              if let  location = venue["location"] as? NSDictionary,
                                name = categoryInfo["name"] as? String,
                                address = location["address"] as? String,
                                lat = location["lat"] as? CLLocationDegrees,
                                long = location["lng"] as? CLLocationDegrees,
                                icon = categoryInfo["icon"] as? NSDictionary,
                                prefix = icon["prefix"] as? String,
                                suffix = icon["suffix"] as? String {
                                    let url = prefix + suffix
                                    let pos = CLLocationCoordinate2DMake(lat, long)
                                    places.append(FourSquarePlace(coordinates: pos, title: name, address: address, imageURL:url, photo: nil))
                            }

和从 SessionAuthorizationDelegate 获取图像的方法

 self.session.downloadImageAtURL(NSURL(string: imageURL)!, completionHandler: { (imageData, error) -> Void in
                    //print(imageData)
                    print(imageURL)
                    if imageData != nil {
                        thisMarker.icon = UIImage(data: imageData!)
                    }
                })

我尝试将 ULR 从儿子粘贴到浏览器并得到它

AccessDeniedAccess DeniedAF1DF956303F2D6EcRetLqGf3ipb6KOsSJ9YkqiDnmEUkjhEavefWCzjlHQAivKWMLsRMQukWsYiVCYK

我猜它可能无法将访问令牌添加到图像,但它很奇怪,因为我使用的是 sdk 方法...

let url = prefix + suffix

这种用法不正确。您必须指定图像的大小。

例如

let url = prefix + "100x100" + suffix

另见 Foursquare API document

To assemble a resolvable photo URL, take prefix + size + suffix, e.g. https://irs0.4sqi.net/img/general/300x500/2341723_vt1Kr-SfmRmdge-M7b4KNgX2_PHElyVbYL65pMnxEQw.jpg.

size can be one of the following, where XX or YY is one of 36, 100, 300, or 500.

  • XXxYY
  • original: the original photo's size
  • capXX: cap the photo with a width or height of XX (whichever is larger). Scales the other, - smaller dimension proportionally
  • widthXX: forces the width to be XX and scales the height proportionally
  • heightYY: forces the height to be YY and scales the width proportionally