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
(DataFlex) Twilio Send SMS (using Chilkat HTTP)Send an outgoing SMS message. For more information, see https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Boolean iSuccess Variant vReq Handle hoReq Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode String sAccount_sid String sApi_version String sBody String sDate_created String sDate_sent String sDate_updated String sDirection String sError_code String sError_message String sFrom String sMessaging_service_sid String sNum_media String sNum_segments String sPrice String sPrice_unit String sSid String sStatus String sSubresource_urisMedia String sV_to String sUri String sTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End // Implements the following CURL command: // (See information about using test credentials and phone numbers: https://www.twilio.com/docs/iam/test-credentials) // curl -X POST https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json \ // --data-urlencode "From=+15005550006" \ // --data-urlencode "Body=body" \ // --data-urlencode "To=+15005551212" \ // -u TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code Set ComLogin Of hoHttp To "TWILIO_ACCOUNT_SID" Set ComPassword Of hoHttp To "TWILIO_AUTH_TOKEN" Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Set ComHttpVerb Of hoReq To "POST" Set ComPath Of hoReq To "/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json" Set ComContentType Of hoReq To "application/x-www-form-urlencoded" Send ComAddParam To hoReq "From" "+15005550006" Send ComAddParam To hoReq "Body" "body" Send ComAddParam To hoReq "To" "+15005551212" Get pvComObject of hoReq to vReq Get ComPostUrlEncoded Of hoHttp "https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json" vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 // A 201 status code indicates success. Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "api_version": "2010-04-01", // "body": "body", // "date_created": "Thu, 30 Jul 2015 20:12:31 +0000", // "date_sent": "Thu, 30 Jul 2015 20:12:33 +0000", // "date_updated": "Thu, 30 Jul 2015 20:12:33 +0000", // "direction": "outbound-api", // "error_code": null, // "error_message": null, // "from": "+15017122661", // "messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "num_media": "0", // "num_segments": "1", // "price": null, // "price_unit": null, // "sid": "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // "status": "sent", // "subresource_uris": { // "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json" // }, // "to": "+15558675310", // "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON Get ComStringOf Of hoJResp "account_sid" To sAccount_sid Get ComStringOf Of hoJResp "api_version" To sApi_version Get ComStringOf Of hoJResp "body" To sBody Get ComStringOf Of hoJResp "date_created" To sDate_created Get ComStringOf Of hoJResp "date_sent" To sDate_sent Get ComStringOf Of hoJResp "date_updated" To sDate_updated Get ComStringOf Of hoJResp "direction" To sDirection Get ComStringOf Of hoJResp "error_code" To sError_code Get ComStringOf Of hoJResp "error_message" To sError_message Get ComStringOf Of hoJResp "from" To sFrom Get ComStringOf Of hoJResp "messaging_service_sid" To sMessaging_service_sid Get ComStringOf Of hoJResp "num_media" To sNum_media Get ComStringOf Of hoJResp "num_segments" To sNum_segments Get ComStringOf Of hoJResp "price" To sPrice Get ComStringOf Of hoJResp "price_unit" To sPrice_unit Get ComStringOf Of hoJResp "sid" To sSid Get ComStringOf Of hoJResp "status" To sStatus Get ComStringOf Of hoJResp "subresource_uris.media" To sSubresource_urisMedia Get ComStringOf Of hoJResp "to" To sV_to Get ComStringOf Of hoJResp "uri" To sUri End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.