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
(Visual FoxPro) Download Photo to a FileAssuming we have the ID of a Photo, this example demonstrates how to download the photo image data to a file.
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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.OAuth2') loOauth2 = CreateObject('Chilkat.OAuth2') loOauth2.AccessToken = "FACEBOOK-ACCESS-TOKEN" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Rest') loRest = CreateObject('Chilkat.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" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbPath = CreateObject('Chilkat.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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbImageUrl = CreateObject('Chilkat.StringBuilder') loSbImageUrl.Append(lcImageUrl) * Build the output local file path. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbToPath = CreateObject('Chilkat.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. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.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-2024 Chilkat Software, Inc. All Rights Reserved.