(Tcl) WhatsApp - Download/Retrieve Media
Demonstrates how to download media previously uploaded to the WhatsApp Business API client For more information, see https://developers.facebook.com/docs/whatsapp/api/media#retrieve
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Implements the following CURL command:
# curl -X GET \
# https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f \
# -H 'Authorization: Bearer your-auth-token' \
# -o path/filename
# Use the following online tool to generate HTTP code from a CURL command
# Convert a cURL Command to HTTP Source Code
# Adds the "Authorization: Bearer your-auth-token" header.
CkHttp_put_AuthToken $http "your-auth-token"
set bdResponseBody [new_CkBinData]
set success [CkHttp_QuickGetBd $http "https://your-webapp-hostname:your-webapp-port/v1/media/4b5bf27b-8672-4d55-bc21-d096dc200d0f" $bdResponseBody]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkBinData $bdResponseBody
exit
}
set respStatusCode [CkHttp_get_LastStatus $http]
puts "response status code = $respStatusCode"
puts "response header = [CkHttp_lastResponseHeader $http]"
if {$respStatusCode != 200} then {
puts "Error response body:"
puts [CkBinData_getString $bdResponseBody utf-8]
delete_CkHttp $http
delete_CkBinData $bdResponseBody
exit
}
set success [CkBinData_WriteFile $bdResponseBody "path/filename"]
delete_CkHttp $http
delete_CkBinData $bdResponseBody
|