|
| Aide API Sphinx dans Windev |
| Iniciado por Dokko5pics, 07,abr. 2020 14:28 - No hay respuesta |
| |
| | | |
|
| |
Miembro registrado 10 mensajes |
|
| Publicado el 07,abril 2020 - 14:28 |
Bonjour à tous,
Je souhaite utiliser l'accès aux API de Sphinx. Mais un première étape est d'obtenir un jeton "token". Sur la page de Sphinx il est écrit : Sphinx WebAPI 4.0
The Sphinx API uses a JSON Web Token based authentication system. You must be authenticated to call the API methods.
To obtain an access token, make an HTTP POST request to https://enquetes-ssa.ac-reunion.fr/SphinxAuth/connect/token with the following parameters: [Content-Type: application/x-www-form-urlencoded] username={accountname}&password={password}&lang={lang}&grant_type=password&client_id=sphinxapiclient
Il est donné aussi une fonction Javascript pour y accéder, mais je n'y connais pas grand chose :
function authenticate(baseUrl, account, personaltoken) { return $.ajax({ type: "POST", url: baseUrl + "/SphinxAuth/connect/token", data: "username=" + account + "&token=" + personaltoken + "&grant_type=personal_token&client_id=sphinxapiclient", contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType: "json", }); }
j'ai essayé plusieurs façons de le faire mais j'y arrive pas :
OKGEO est un boolean geo est un JSON sUsername est une chaîne ANSI="user" motdepasse est une chaîne ANSI ="motdepasse" Data , sMonurl sont des chaînes ANSI Sablier() Trace("Methode 1") sMonurl = "https://enquetes-ssa.ac-reunion.fr/SphinxAuth/connect/token" Data= "username=" + sUsername + "&token=" + motdepasse + "&grant_type=personal_token&client_id=sphinxapiclient"+"ContentType="+"application/x-www-form-urlencoded; charset=utf-8" cMaRequete est un restRequête cMaRequete..Méthode = httpPost cMaRequete..URL = URLEncode(sMonurl + Data ) cMaReponse est un restRéponse = RESTEnvoie ( cMaRequete )
SI ErreurDétectée ALORS Erreur ( "KO" , ErreurInfo ( errComplet )) OKGEO=Faux SINON OKGEO = Vrai geo = cMaReponse..Contenu FIN Trace("La réponse methode 1 " +cMaReponse..Contenu) Trace("Methode 2") account est une chaîne ANSI="account" personaltoken est une chaîne ANSI ="motdepasse" req est un httpRequête Rep est un httpRéponse req.Méthode=httpPost req.URL=URLEncode(sMonurl) req.Entête["contentType"]=URLEncode("application/x-www-form-urlencoded; charset=utf-8") req.Entête["data"]=URLEncode("username=" + account + "&token=" + personaltoken + "&grant_type=personal_token&client_id=sphinxapiclient") req.Entête["dataType"]="json" Rep = HTTPEnvoie(req)
SI ErreurDétectée ALORS Erreur(ErreurInfo(errComplet)) SINON Trace("La réponse methode 2 " +Rep..Contenu) FIN Trace("Methode 3 ")
codeJS est chaîne = [ return $.ajax({ type: "POST", url: baseUrl + "/SphinxAuth/connect/token", data: "username=" + "PJE" + "&token=" + "Ss@run974!" + "&grant_type=personal_token&client_id=sphinxapiclient", contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType: "json", }); } ] ExecuteJS(HTM_SansNom1, codeJS)
Sablier(Faux)
Dans la méthode 3 je tente d'utiliser la fonction Javascript donné par Sphinx. Mais rien ne fonctionne.
Grand merci à vous pour votre aide. |
| |
| |
| | | |
|
| | | | |
| | |
|