![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) Banco Inter OAuth2 Client CredentialsGenerate an OAuth2 access token needed to consume the Inter APIs. Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://developers.bancointer.com.br/reference/token-3
LOCAL lnSuccess LOCAL loHttp LOCAL loCert LOCAL loBdPrivKey LOCAL loPrivKey LOCAL loReq LOCAL loResp LOCAL loJResp LOCAL lnRespStatusCode lnSuccess = 0 * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. loHttp = CreateObject('Chilkat.Http') * First load the certificate and private key, and set as the HTTP object's client certificate. loCert = CreateObject('Chilkat.Cert') lnSuccess = loCert.LoadFromFile("<nome arquivo certificado>.crt") IF (lnSuccess = 0) THEN ? loCert.LastErrorText RELEASE loHttp RELEASE loCert CANCEL ENDIF loBdPrivKey = CreateObject('Chilkat.BinData') lnSuccess = loBdPrivKey.LoadFile("<nome arquivo chave privada>.key") IF (lnSuccess = 0) THEN ? "Failed to load <nome" RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey CANCEL ENDIF loPrivKey = CreateObject('Chilkat.PrivateKey') lnSuccess = loPrivKey.LoadAnyFormat(loBdPrivKey,"") IF (lnSuccess = 0) THEN ? loPrivKey.LastErrorText RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey CANCEL ENDIF lnSuccess = loCert.SetPrivateKey(loPrivKey) IF (lnSuccess = 0) THEN ? loCert.LastErrorText RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey CANCEL ENDIF lnSuccess = loHttp.SetSslClientCert(loCert) IF (lnSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey CANCEL ENDIF loReq = CreateObject('Chilkat.HttpRequest') loReq.HttpVerb = "POST" loReq.Path = "/oauth/v2/token" loReq.ContentType = "application/x-www-form-urlencoded" loReq.AddParam("grant_type","client_credentials") * Requested scopes in OAuth2 are typically SPACE separated. loReq.AddParam("scope","boleto-cobranca.read boleto-cobranca.write") loReq.AddHeader("accept","application/json") loResp = CreateObject('Chilkat.HttpResponse') lnSuccess = loHttp.HttpReq("https://cdpj.partners.bancointer.com.br/oauth/v2/token",loReq,loResp) IF (lnSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey RELEASE loReq RELEASE loResp CANCEL ENDIF loJResp = CreateObject('Chilkat.JsonObject') loResp.GetBodyJson(loJResp) loJResp.EmitCompact = 0 ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + STR(lnRespStatusCode) IF (lnRespStatusCode >= 400) THEN ? "Response Header:" ? loResp.Header ? "Failed." RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey RELEASE loReq RELEASE loResp RELEASE loJResp CANCEL ENDIF lnSuccess = loJResp.WriteFile("qa_data/tokens/banco_inter_client_credentials.json") IF (lnSuccess = 0) THEN ? "Failed to save JSON access token file." RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey RELEASE loReq RELEASE loResp RELEASE loJResp CANCEL ENDIF ? "Success." RELEASE loHttp RELEASE loCert RELEASE loBdPrivKey RELEASE loPrivKey RELEASE loReq RELEASE loResp RELEASE loJResp |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.