Chilkat Examples

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

Visual FoxPro Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon DynamoDB
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CallRail
CardConnect
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
ETrade
Etsy
Facebook
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
Lightspeed
MYOB

Magento
MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SMSAPI
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WiX
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Visual FoxPro) Download Photo to a File

Assuming we have the ID of a Photo, this example demonstrates how to download the photo image data to a file.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loOauth2
LOCAL loRest
LOCAL lnSuccess
LOCAL lcPhotoId
LOCAL loSbPath
LOCAL lcResponseJson
LOCAL loJson
LOCAL lcImageUrl
LOCAL loSbImageUrl
LOCAL loSbToPath
LOCAL lnBCaseSensitive
LOCAL loHttp

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

* This example assumes a previously obtained an access token
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "FACEBOOK-ACCESS-TOKEN"

loRest = CreateObject('Chilkat_9_5_0.Rest')

* Connect to Facebook...
lnSuccess = loRest.Connect("graph.facebook.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loOauth2
    RELEASE loRest
    CANCEL
ENDIF

* Provide the authentication credentials (i.e. the access key)
loRest.SetAuthOAuth2(loOauth2)

* Assumes we've already obtained a Photo ID.
lcPhotoId = "10210199026347451"

loSbPath = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbPath.Append("/v2.7/")
loSbPath.Append(lcPhotoId)

* First we're going to get the photo informaton so we can get the URL of the image file data.
* Select the fields we want.
* See https://developers.facebook.com/docs/graph-api/reference/photo/
loRest.AddQueryParam("fields","id,album,images")

lcResponseJson = loRest.FullRequestNoBody("GET",loSbPath.GetAsString())
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loOauth2
    RELEASE loRest
    RELEASE loSbPath
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.EmitCompact = 0
loJson.Load(lcResponseJson)

* Show the JSON in human-readable format.
? loJson.Emit()

* Get the image URL.
lcImageUrl = loJson.StringOf("images[0].source")
? "Downloading from " + lcImageUrl

loSbImageUrl = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbImageUrl.Append(lcImageUrl)

* Build the output local file path.
loSbToPath = CreateObject('Chilkat_9_5_0.StringBuilder')
loSbToPath.Append("qa_output/fb")
loSbToPath.Append(loJson.StringOf("id"))
lnBCaseSensitive = 0
IF (loSbImageUrl.Contains(".jpg",lnBCaseSensitive) = 1) THEN
    loSbToPath.Append(".jpg")
ELSE
    loSbToPath.Append(".png")
ENDIF

? "Downloading to " + loSbToPath.GetAsString()

* Download using Chilkat HTTP.
loHttp = CreateObject('Chilkat_9_5_0.Http')
lnSuccess = loHttp.Download(lcImageUrl,loSbToPath.GetAsString())
IF (lnSuccess <> 1) THEN
    ? loHttp.LastErrorText
ELSE
    ? "Downloaded."
ENDIF

RELEASE loOauth2
RELEASE loRest
RELEASE loSbPath
RELEASE loJson
RELEASE loSbImageUrl
RELEASE loSbToPath
RELEASE loHttp


 

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