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
(Unicode C) Twilio Send MMS (using Chilkat HTTP)Send an outgoing MMS message. The only difference with MMS (as compared with SMS) is that a MediaUrl parameter is added to the POST. This means your image must be accessible on the web -- the Twilio server must be able to download the image from the URL you provide to include it in the MMS mesage to be sent. Also, see Twilio MMS for more information about MMS. For more information, see https://support.twilio.com/hc/en-us/articles/223179808-Sending-and-receiving-MMS-messages
#include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> #include <C_CkDtObjW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkHttpRequestW req; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; HCkDtObjW date_created; HCkDtObjW date_updated; HCkDtObjW date_sent; const wchar_t *sid; const wchar_t *account_sid; const wchar_t *v_to; const wchar_t *from; const wchar_t *messaging_service_sid; const wchar_t *body; const wchar_t *status; const wchar_t *num_segments; const wchar_t *num_media; const wchar_t *direction; const wchar_t *api_version; const wchar_t *price; const wchar_t *price_unit; const wchar_t *error_code; const wchar_t *error_message; const wchar_t *uri; const wchar_t *subresource_urisMedia; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // 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 CkHttpW_putLogin(http,L"TWILIO_ACCOUNT_SID"); CkHttpW_putPassword(http,L"TWILIO_AUTH_TOKEN"); req = CkHttpRequestW_Create(); CkHttpRequestW_putHttpVerb(req,L"POST"); CkHttpRequestW_putPath(req,L"/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json"); CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded"); CkHttpRequestW_AddParam(req,L"From",L"+15005550006"); CkHttpRequestW_AddParam(req,L"Body",L"body"); CkHttpRequestW_AddParam(req,L"To",L"+15005551212"); CkHttpRequestW_AddParam(req,L"MediaUrl",L"https://www.chilkatsoft.com/images/starfish.jpg"); resp = CkHttpW_PostUrlEncoded(http,L"https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json",req); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); // A 201 status code indicates success. respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "sid": "SM477111c301794f14b11eca5eefd5c350", // "date_created": "Tue, 18 Aug 2020 15:04:47 +0000", // "date_updated": "Tue, 18 Aug 2020 15:04:47 +0000", // "date_sent": null, // "account_sid": "AC2e9b6bc0f51133df24926f07341d3824", // "to": "+15005551212", // "from": "+15005550006", // "messaging_service_sid": null, // "body": "body", // "status": "queued", // "num_segments": "1", // "num_media": "0", // "direction": "outbound-api", // "api_version": "2010-04-01", // "price": null, // "price_unit": "USD", // "error_code": null, // "error_message": null, // "uri": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350.json", // "subresource_uris": { // "media": "/2010-04-01/Accounts/AC2e9b6bc0f51133df24926f07341d3824/Messages/SM477111c301794f14b11eca5eefd5c350/Media.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 date_created = CkDtObjW_Create(); date_updated = CkDtObjW_Create(); date_sent = CkDtObjW_Create(); sid = CkJsonObjectW_stringOf(jResp,L"sid"); CkJsonObjectW_DtOf(jResp,L"date_created",FALSE,date_created); CkJsonObjectW_DtOf(jResp,L"date_updated",FALSE,date_updated); CkJsonObjectW_DtOf(jResp,L"date_sent",FALSE,date_sent); account_sid = CkJsonObjectW_stringOf(jResp,L"account_sid"); v_to = CkJsonObjectW_stringOf(jResp,L"to"); from = CkJsonObjectW_stringOf(jResp,L"from"); messaging_service_sid = CkJsonObjectW_stringOf(jResp,L"messaging_service_sid"); body = CkJsonObjectW_stringOf(jResp,L"body"); status = CkJsonObjectW_stringOf(jResp,L"status"); num_segments = CkJsonObjectW_stringOf(jResp,L"num_segments"); num_media = CkJsonObjectW_stringOf(jResp,L"num_media"); direction = CkJsonObjectW_stringOf(jResp,L"direction"); api_version = CkJsonObjectW_stringOf(jResp,L"api_version"); price = CkJsonObjectW_stringOf(jResp,L"price"); price_unit = CkJsonObjectW_stringOf(jResp,L"price_unit"); error_code = CkJsonObjectW_stringOf(jResp,L"error_code"); error_message = CkJsonObjectW_stringOf(jResp,L"error_message"); uri = CkJsonObjectW_stringOf(jResp,L"uri"); subresource_urisMedia = CkJsonObjectW_stringOf(jResp,L"subresource_uris.media"); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); CkDtObjW_Dispose(date_created); CkDtObjW_Dispose(date_updated); CkDtObjW_Dispose(date_sent); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.