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

Delphi ActiveX 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

 

 

 

(Delphi ActiveX) MYOB Extend Refresh Access Token

Refreshes the access token for MYOB apps.

Chilkat for Delphi Downloads

Chilkat ActiveX DLL for Delphi

Chilkat non-ActiveX DLL for Delphi

* The examples here use the ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_v9_5_0_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
jsonToken: TChilkatJsonObject;
success: Integer;
oauth2: TChilkatOAuth2;
sbJson: TChilkatStringBuilder;

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

// See Get MYOB Access Token 
// for sample code showing how to obtain a MYOB access token for desktop apps.

jsonToken := TChilkatJsonObject.Create(Self);
success := jsonToken.LoadFile('qa_data/tokens/myob.json');
if (success <> 1) then
  begin
    Memo1.Lines.Add('Failed to load myob.json');
    Exit;
  end;

oauth2 := TChilkatOAuth2.Create(Self);

oauth2.TokenEndpoint := 'https://secure.myob.com/oauth2/v1/authorize/';

// Replace these with actual values.
oauth2.ClientId := 'CLIENT_ID';
oauth2.ClientSecret := 'CLIENT_SECRET';

// Get the "refresh_token"
oauth2.RefreshToken := jsonToken.StringOf('refresh_token');

// Send the HTTP POST to refresh the access token..
oauth2.VerboseLogging := 1;
success := oauth2.RefreshAccessToken();
if (success <> 1) then
  begin
    Memo1.Lines.Add(oauth2.LastErrorText);
    Exit;
  end;

// Load the access token response into the json object 
jsonToken.Load(oauth2.AccessTokenResponse);

// Save the new JSON access token response to a file.
// The access + refresh tokens contained in this JSON will be needed for the next refresh.
sbJson := TChilkatStringBuilder.Create(Self);
jsonToken.EmitCompact := 0;
jsonToken.EmitSb(sbJson.ControlInterface);
sbJson.WriteFile('qa_data/tokens/myob.json','utf-8',0);

Memo1.Lines.Add('OAuth2 authorization granted!');
Memo1.Lines.Add('New Access Token = ' + oauth2.AccessToken);
end;

 

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