Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) GeoOp Exchange Refresh Token for New Access TokenDemonstrates how to use the /oauth2/token endpoint to exchange it for a new access token once the current access token has expired. Note: This example requires Chilkat v9.5.0.65 or greater.
Use ChilkatAx-win32.pkg Procedure Test Token Handle hoJsonToken Boolean iSuccess Handle hoRest Boolean iBAutoReconnect String sResponseBody Handle hoJson String sTemp1 Integer iTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // This example also assumes that OAuth2 access and refresh tokens were previously fetched. // and saved in a JSON file. // First get our previously obtained refresh token. // { .... "refresh_token":"e6dqdG....mzjpT04w==", .... } Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken If (Not(IsComObjectCreated(hoJsonToken))) Begin Send CreateComObject of hoJsonToken End Get ComLoadFile Of hoJsonToken "qa_data/tokens/geoop.json" To iSuccess Get Create (RefClass(cComChilkatRest)) To hoRest If (Not(IsComObjectCreated(hoRest))) Begin Send CreateComObject of hoRest End // Connect to GeoOp... Move True To iBAutoReconnect Get ComConnect Of hoRest "login.geoop.com" 443 True iBAutoReconnect To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End // Set the X-Version header. Get ComAddHeader Of hoRest "X-Version" "1.0" To iSuccess // Provide the required form params to get the new access token Get ComStringOf Of hoJsonToken "refresh_token" To sTemp1 Showln "refresh_token = " sTemp1 Get ComStringOf Of hoJsonToken "refresh_token" To sTemp1 Get ComAddQueryParam Of hoRest "refresh_token" sTemp1 To iSuccess Get ComAddQueryParam Of hoRest "grant_type" "refresh_token" To iSuccess Get ComAddQueryParam Of hoRest "client_id" "GEOOP-CLIENT-ID" To iSuccess Get ComAddQueryParam Of hoRest "client_secret" "GEOOP-CLIENT-SECRET" To iSuccess Get ComFullRequestFormUrlEncoded Of hoRest "POST" "/oauth2/token" To sResponseBody Get ComLastMethodSuccess Of hoRest To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End // If the response status code did not indicate success, then see what happened.. Get ComResponseStatusCode Of hoRest To iTemp1 If (iTemp1 <> 200) Begin Showln "Request Header: " Get ComLastRequestHeader Of hoRest To sTemp1 Showln sTemp1 Showln "----" Get ComResponseStatusCode Of hoRest To iTemp1 Showln "Response StatusCode = " iTemp1 Get ComResponseStatusText Of hoRest To sTemp1 Showln "Response StatusLine: " sTemp1 Showln "Response Header:" Get ComResponseHeader Of hoRest To sTemp1 Showln sTemp1 Showln sResponseBody Procedure_Return End Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Set ComEmitCompact Of hoJson To False Get ComLoad Of hoJson sResponseBody To iSuccess // Show the full JSON response. It should contain the new access token... Get ComEmit Of hoJson To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.