|  | 
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
| (Delphi DLL) WhatsApp - Change a User PasswordDemonstrates how to change the password for a WhatsApp Business API user account. Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://developers.facebook.com/docs/whatsapp/api/users/manage 
 uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; http: HCkHttp; json: HCkJsonObject; sbRequestBody: HCkStringBuilder; resp: HCkHttpResponse; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; username: PWideChar; i: Integer; count_i: Integer; begin success := False; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // Implements the following CURL command: // curl -X PUT https://example.com/v1/users/username \ // -H "Authorization: Bearer your-auth-token" \ // -d '{"password": "new-password"}' // The following JSON is sent in the request body. // { // "password": "new-password" // } json := CkJsonObject_Create(); CkJsonObject_UpdateString(json,'password','new-password'); // Adds the "Authorization: Bearer your-auth-token" header. CkHttp_putAuthToken(http,'your-auth-token'); sbRequestBody := CkStringBuilder_Create(); CkJsonObject_EmitSb(json,sbRequestBody); resp := CkHttpResponse_Create(); success := CkHttp_HttpSb(http,'PUT','https://example.com/v1/users/username',sbRequestBody,'utf-8','application/json',resp); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; sbResponseBody := CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttpResponse_getStatusCode(resp); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttpResponse__header(resp)); Memo1.Lines.Add('Failed.'); Exit; end; // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "users": [ // { // "username": "username" // } // ] // } // Sample code for parsing the JSON response... i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'users'); while i < count_i do begin CkJsonObject_putI(jResp,i); username := CkJsonObject__stringOf(jResp,'users[i].username'); i := i + 1; end; CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbRequestBody); CkHttpResponse_Dispose(resp); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; | ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.