gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:38 25 4
gpt4 key购买 nike

我正在为 swift (QuadratTouch) 使用 das quadrat foursquare sdk一切正常,期待得到图像他们在像 NSDictionary 这样的 JSON 中用“前缀”和“后缀”标记和 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

我猜它可能无法将访问 token 添加到图像,但它很奇怪,因为我正在使用 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

关于ios - 无法在 swift iOS 上从 foursquare api 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32910653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com