ios - 谷歌网址缩短器 iOS

标签 ios swift google-api xcode7 afnetworking-3

尝试使用 GoogleShortener API 获取简短版本的 URL。 我正在使用 AFNetworking 3.0,但出现此错误:'AnyObject 不是'NSProxy'的子类型

let manager = AFHTTPSessionManager()
    manager.requestSerializer = AFJSONRequestSerializer()
    let params = ["longUrl": "MYURL"]


    manager.POST("https://www.googleapis.com/urlshortener/v1/url?key=MYKEY", parameters: params, success: {(operation: NSURLSession!,responseObject: AnyObject!) in
        println("JSON" + responseObject.description)
        },


                 failure: { (operation: NSURLSession!,error: NSError!) in
        println("Error while requesting shortened: " + error.localizedDescription)
    })

它在行 'println("JSON"+ responseObject.description)' 中突出显示 关于“描述”的请求。

最佳答案

我在使用 AFNetworking 3 时遇到了同样的错误。文档表明有一些更改。但是,这是我能够运行的代码。希望一切顺利。

let manager = AFHTTPSessionManager()
manager.requestSerializer = AFJSONRequestSerializer()
let params = ["longUrl": "MYURL"]


manager.POST("https://www.googleapis.com/urlshortener/v1/url?key=MYKEY", parameters: params, success: {(operation: NSURLSessionDataTask!,responseObject: AnyObject?) in
    print("JSON" + (responseObject?.description)!)
    },


             failure: { (operation: NSURLSessionDataTask?,error: NSError) in
    print("Error while requesting shortened: " + error.localizedDescription)
})

关于ios - 谷歌网址缩短器 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37111275/

相关文章:

ios - Swift 中的@dynamicCallable 是什么?

azure - 使用 Azure Functions 中的 Google API

ios - 无法从呈现的 View Controller 访问 TopView

swift - 我如何确定一个正方形是否可以在不与其他 Sprite 接触的情况下到达位置?

iphone - 在 UIButton 中针对不同的文本大小设置图像对齐方式

rest - 如何从 YouTube channel 获取直播视频 ID

python - 从 Google Maps API v3 获取纬度和经度

ios - 后退按钮启动 UIViewPropertyAnimator?

ios - 在 UIImageView 动画上停止 Alpha 混合

ios - UNUserNotificationCenter 链接错误