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
(AutoIt) 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.
; 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 $oOauth2 = ObjCreate("Chilkat.OAuth2") $oOauth2.AccessToken = "FACEBOOK-ACCESS-TOKEN" $oRest = ObjCreate("Chilkat.Rest") ; Connect to Facebook... Local $bSuccess = $oRest.Connect("graph.facebook.com",443,True,True) If ($bSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf ; Provide the authentication credentials (i.e. the access key) $oRest.SetAuthOAuth2($oOauth2) ; Assumes we've already obtained a Photo ID. Local $sPhotoId = "10210199026347451" $oSbPath = ObjCreate("Chilkat.StringBuilder") $oSbPath.Append("/v2.7/") $oSbPath.Append($sPhotoId) ; 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/ $oRest.AddQueryParam("fields","id,album,images") Local $sResponseJson = $oRest.FullRequestNoBody("GET",$oSbPath.GetAsString()) If ($oRest.LastMethodSuccess <> True) Then ConsoleWrite($oRest.LastErrorText & @CRLF) Exit EndIf $oJson = ObjCreate("Chilkat.JsonObject") $oJson.EmitCompact = False $oJson.Load($sResponseJson) ; Show the JSON in human-readable format. ConsoleWrite($oJson.Emit() & @CRLF) ; Get the image URL. Local $sImageUrl = $oJson.StringOf("images[0].source") ConsoleWrite("Downloading from " & $sImageUrl & @CRLF) $oSbImageUrl = ObjCreate("Chilkat.StringBuilder") $oSbImageUrl.Append($sImageUrl) ; Build the output local file path. $oSbToPath = ObjCreate("Chilkat.StringBuilder") $oSbToPath.Append("qa_output/fb") $oSbToPath.Append($oJson.StringOf("id")) Local $bCaseSensitive = False If ($oSbImageUrl.Contains(".jpg",$bCaseSensitive) = True) Then $oSbToPath.Append(".jpg") Else $oSbToPath.Append(".png") EndIf ConsoleWrite("Downloading to " & $oSbToPath.GetAsString() & @CRLF) ; Download using Chilkat HTTP. $oHttp = ObjCreate("Chilkat.Http") $bSuccess = $oHttp.Download($sImageUrl,$oSbToPath.GetAsString()) If ($bSuccess <> True) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Else ConsoleWrite("Downloaded." & @CRLF) EndIf |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.