编辑代码

import UIKit
import Foundation
let API_Key= "EIpAlhdD715152Es1NqpU0F"
let Secret Key ="p8EZNg4agjDOxABmKvBYSNyZ1Y2GFqb_”
lettoken host "https://aip.baidubce.com/oauth/2.0/token?granttype=client_credentialskclfent_id=\(API_Key)&client_secret=\(Secret Key)"
var access token
var expires in :Int32=0
if let url= URL(string: token host)
一
URLSession.shared.dataTask(with: url) (data, response, error) in if error !=nil (
print("network error")
)
else
if let ison = try? JSONSeralization.fsonObject(with: data! options: .allowFragment.s) as? [String:Anyl 一
access token = json["access_token"] as! String
expizes_in - json["expiros_in"] as! Int32
print(" -access coken------")
print(access_token)
print("- -----expires time------")
print(expires_in)
.resume()
}
else{
print("url error")
}