Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Google Maps Geolocation Request

Demonstrates how make a Google Maps Geolocation REST API request.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
integer li_Success
oleobject loo_Json
oleobject loo_ACellTowers
oleobject loo_OCellTower
oleobject loo_AWifi
oleobject loo_OPoint
string ls_ResponseJson
oleobject loo_JsonResp
oleobject loo_JsonLoc
string ls_Latitude
string ls_Longitude
string ls_Accuracy

// This example duplicates the following CURL request:
// curl -d @your_filename.json -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY"

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

loo_Rest = create oleobject
// Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Connect to the Google API REST server.
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("www.googleapis.com",li_Port,li_BTls,li_BAutoReconnect)

// Add the Content-Type request header.
loo_Rest.AddHeader("Content-Type","application/json")

// Add your API key as a query parameter
loo_Rest.AddQueryParam("key","YOUR_API_KEY")

// The JSON query is contained in the body of the HTTP POST.
// This is a sample query (which we'll dynamically build in this example)
// { 
//  "homeMobileCountryCode": 310,
//  "homeMobileNetworkCode": 260,
//  "radioType": "gsm",
//  "carrier": "T-Mobile",
//  "cellTowers": [
//   {
//    "cellId": 39627456,
//    "locationAreaCode": 40495,
//    "mobileCountryCode": 310,
//    "mobileNetworkCode": 260,
//    "age": 0,
//    "signalStrength": -95
//   }
//  ],
//  "wifiAccessPoints": [
//   { 
//    "macAddress": "01:23:45:67:89:AB",
//    "signalStrength": 8,
//    "age": 0,
//    "signalToNoiseRatio": -65,
//    "channel": 8
//   },
//   { 
//    "macAddress": "01:23:45:67:89:AC",
//    "signalStrength": 4,
//    "age": 0
//   }
//  ]
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.AppendInt("homeMobileCountryCode",310)
loo_Json.AppendInt("homeMobileNetworkCode",260)
loo_Json.AppendString("radioType","gsm")
loo_Json.AppendString("carrier","T-Mobile")
loo_ACellTowers = loo_Json.AppendArray("cellTowers")
loo_ACellTowers.AddObjectAt(0)
loo_OCellTower = loo_ACellTowers.ObjectAt(0)
loo_OCellTower.AppendInt("cellId",39627456)
loo_OCellTower.AppendInt("locationAreaCode",40495)
loo_OCellTower.AppendInt("mobileCountryCode",310)
loo_OCellTower.AppendInt("mobileNetworkCode",260)
loo_OCellTower.AppendInt("age",0)
loo_OCellTower.AppendInt("signalStrength",-95)
destroy loo_OCellTower
destroy loo_ACellTowers
loo_AWifi = loo_Json.AppendArray("wifiAccessPoints")
loo_AWifi.AddObjectAt(0)
loo_OPoint = loo_AWifi.ObjectAt(0)
loo_OPoint.AppendString("macAddress","01:23:45:67:89:AB")
loo_OPoint.AppendInt("signalStrength",8)
loo_OPoint.AppendInt("age",0)
loo_OPoint.AppendInt("signalToNoiseRatio",-65)
loo_OPoint.AppendInt("channel",8)
destroy loo_OPoint
loo_AWifi.AddObjectAt(1)
loo_OPoint = loo_AWifi.ObjectAt(1)
loo_OPoint.AppendString("macAddress","01:23:45:67:89:AC")
loo_OPoint.AppendInt("signalStrength",4)
loo_OPoint.AppendInt("age",0)
destroy loo_OPoint
destroy loo_AWifi

ls_ResponseJson = loo_Rest.FullRequestString("POST","/geolocation/v1/geolocate",loo_Json.Emit())
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Json
    return
end if

// When successful, the response code is 200.
if loo_Rest.ResponseStatusCode <> 200 then
    // Examine the request/response to see what happened.
    Write-Debug "response status code = " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "response status text = " + loo_Rest.ResponseStatusText
    Write-Debug "response header: " + loo_Rest.ResponseHeader
    Write-Debug "response JSON: " + ls_ResponseJson
    Write-Debug "---"
    Write-Debug "LastRequestStartLine: " + loo_Rest.LastRequestStartLine
    Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader
    destroy loo_Rest
    destroy loo_Json
    return
end if

loo_Json.EmitCompact = 0
Write-Debug "JSON request body: " + loo_Json.Emit()

// The JSON response should look like this:
// { 
//  "location": {
//   "lat": 37.4248297,
//   "lng": -122.07346549999998
//  },
//  "accuracy": 1145.0
// }

Write-Debug "JSON response: " + ls_ResponseJson

loo_JsonResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonResp.Load(ls_ResponseJson)

loo_JsonLoc = loo_JsonResp.ObjectOf("location")
// Any JSON value can be obtained as a string..
ls_Latitude = loo_JsonLoc.StringOf("lat")
Write-Debug "latitude = " + ls_Latitude
ls_Longitude = loo_JsonLoc.StringOf("lng")
Write-Debug "longitude = " + ls_Longitude
destroy loo_JsonLoc

ls_Accuracy = loo_JsonResp.StringOf("accuracy")
Write-Debug "accuracy = " + ls_Accuracy


destroy loo_Rest
destroy loo_Json
destroy loo_JsonResp

 

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