I'm trying to add short url in my app as a tool for the users and this is what a came with from this answer and unfortunately it didn't work! :
import AFNetworking
let googleShortURLKey = "MYKEY"
func getShortURLFromGoogle(longURL: String) {
let manager = AFHTTPSessionManager()
manager.requestSerializer = AFJSONRequestSerializer() as AFJSONRequestSerializer
let params = [ "longUrl": longURL ]
manager.POST("https://www.googleapis.com/urlshortener/v1/url?key=\(googleShortURLKey)", parameters: params, success: {
(operation: AFHTTPRequestSerializer!,responseObject: AnyObject!) in
if let responseObject = responseObject as? NSDictionary {
self.shortURL = responseObject["id"] as? String //That's what you want
}
},
failure: { (operation: AFHTTPRequestSerializer!,error: NSError!) in
print("Error while requesting shortened: " + error.localizedDescription)
})
}