8
Je cherche à récupérer un jeton OAuth pour utiliser l'API Fusion Yelp à partir d'un client iOS en utilisant l'URL native et les classes URLRequest, mais il me donne cette erreur dans la variable "tokenInfo":iOS Yelp Jeton OAuth Retrieval avec URLRequest retour « paramètres client_id ou client_secret pas trouvé
client_id or client_secret parameters not found. Make sure to provide
client_id and client_secret in the body with the
application/x-www-form-urlencoded content-type
Voici mon code:
func getToken(){
var yelpTokenEndpoint = "https://api.yelp.com/oauth2/token"
var tokenURL = URL(string: yelpTokenEndpoint)
let requestJSON: [String:String] = ["client_id":"Not showing actual client id", "client_secret":"Not Gonna Show My Actual Client Secret either","grant_type":"client_credentials"]
let requestData = try? JSONSerialization.data(withJSONObject: requestJSON)
print(try? JSONSerialization.jsonObject(with: requestData!, options: []))
var tokenURLRequest = URLRequest(url: tokenURL!)
tokenURLRequest.httpMethod = "POST"
tokenURLRequest.httpBody = requestData!
tokenURLRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
let tokenSession = URLSession.shared
let tokenTask = tokenSession.dataTask(with: tokenURLRequest) { (data, response, error) in
if error != nil {
print("error getting your access token")
print(error!.localizedDescription)
}
if let data = data{
do{
if let tokenInfo = try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any]{
let token: String = tokenInfo["access_token"] as! String
print(token)
}
} catch {
print("Error converting to JSON")
}
}
}
tokenTask.resume()
}
Et oui, je suis certain que je mets les informations d'identification du client droit à toute aide serait très apprécié, merci.!