Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Visual FoxPro Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(Visual FoxPro) Group: Refresh OAuth2 Access Token

Refreshes an expired or non-expired OAuth2 access token for the Microsoft Group REST API.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loJson
LOCAL lnSuccess
LOCAL loReq
LOCAL loHttp
LOCAL loResp
LOCAL loFac

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
lnSuccess = loJson.LoadFile("qa_data/tokens/msGraphGroup.json")
IF (lnSuccess <> 1) THEN
    RELEASE loJson
    CANCEL
ENDIF

loReq = CreateObject('Chilkat_9_5_0.HttpRequest')
loReq.AddParam("grant_type","refresh_token")
loReq.AddParam("redirect_uri","http://localhost:3017/")
loReq.AddParam("client_id","MICROSOFT-GRAPH-CLIENT-ID")
loReq.AddParam("client_secret","MICROSOFT-GRAPH-CLIENT-SECRET")
loReq.AddParam("refresh_token",loJson.StringOf("refresh_token"))
loReq.AddParam("scope","openid profile offline_access user.readwrite group.readwrite.all files.readwrite")

loHttp = CreateObject('Chilkat_9_5_0.Http')

loResp = loHttp.PostUrlEncoded("https://login.microsoftonline.com/common/oauth2/v2.0/token",loReq)
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loJson
    RELEASE loReq
    RELEASE loHttp
    CANCEL
ENDIF

* Load the JSON response.
loJson.Load(loResp.BodyStr)
loJson.EmitCompact = 0

* Show the JSON response.
? loJson.Emit()

? "Response status code: " + STR(loResp.StatusCode)

* If the response status code is not 200, then it's an error.
IF (loResp.StatusCode <> 200) THEN
    RELEASE loJson
    RELEASE loReq
    RELEASE loHttp
    CANCEL
ENDIF

RELEASE loResp

* Save the refreshed access token JSON to a file for future requests.
loFac = CreateObject('Chilkat_9_5_0.FileAccess')
loFac.WriteEntireTextFile("qa_data/tokens/msGraphGroup.json",loJson.Emit(),"utf-8",0)

? "Success."

RELEASE loJson
RELEASE loReq
RELEASE loHttp
RELEASE loFac


 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.