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
(Tcl) WordPress Basic Authentication with miniOrange PluginSee more WordPress ExamplesDemonstrates basic username/password authentication using the miniOrange API Authentication plugin. For more information, see https://wordpress.org/plugins/wp-rest-api-authentication/
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 --user wp_username:wp_password https://www.yoursite.com/wp-json/wp/v2/posts?page=1 # Use the following online tool to generate HTTP code from a CURL command # Convert a cURL Command to HTTP Source Code CkHttp_put_Login $http "wp_username" CkHttp_put_Password $http "wp_password" CkHttp_put_BasicAuth $http 1 set sbResponseBody [new_CkStringBuilder] set success [CkHttp_QuickGetSb $http "https://www.yoursite.com/wp-json/wp/v2/posts?page=1" $sbResponseBody] if {$success == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkStringBuilder $sbResponseBody exit } set jarrResp [new_CkJsonArray] CkJsonArray_LoadSb $jarrResp $sbResponseBody CkJsonArray_put_EmitCompact $jarrResp 0 puts "Response Body:" puts [CkJsonArray_emit $jarrResp] set respStatusCode [CkHttp_get_LastStatus $http] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttp_lastHeader $http] puts "Failed." delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonArray $jarrResp exit } # Sample JSON response: # (Sample code for parsing the JSON response is shown below) # [ # { # "id": 1902, # "date": "2020-11-16T09:54:09", # "date_gmt": "2020-11-16T16:54:09", # "guid": { # "rendered": "http:\/\/cknotes.com\/?p=1902" # }, # "modified": "2020-11-16T09:54:09", # "modified_gmt": "2020-11-16T16:54:09", # "slug": "xero-redirect-uri-for-oauth2-and-desktop-apps", # "status": "publish", # "type": "post", # "link": "https:\/\/cknotes.com\/xero-redirect-uri-for-oauth2-and-desktop-apps\/", # "title": { # "rendered": "Xero Redirect URI for OAuth2 and Desktop Apps" # }, # "content": { # "rendered": "<p>...", # "protected": false # }, # "excerpt": { # "rendered": "<p>...", # "protected": false # }, # "author": 1, # "featured_media": 0, # "comment_status": "closed", # "ping_status": "open", # "sticky": false, # "template": "", # "format": "standard", # "meta": [ # ], # "categories": [ # 815 # ], # "tags": [ # 594, # 816 # ], # "_links": { # "self": [ # { # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902" # } # ], # "collection": [ # { # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts" # } # ], # "about": [ # { # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/post" # } # ], # "author": [ # { # "embeddable": true, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1" # } # ], # "replies": [ # { # "embeddable": true, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=1902" # } # ], # "version-history": [ # { # "count": 1, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions" # } # ], # "predecessor-version": [ # { # "id": 1904, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/posts\/1902\/revisions\/1904" # } # ], # "wp:attachment": [ # { # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media?parent=1902" # } # ], # "wp:term": [ # { # "taxonomy": "category", # "embeddable": true, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/categories?post=1902" # }, # { # "taxonomy": "post_tag", # "embeddable": true, # "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/tags?post=1902" # } # ], # "curies": [ # { # "name": "wp", # "href": "https:\/\/api.w.org\/{rel}", # "templated": true # } # ] # } # }, # ... # ] # Sample code for parsing the JSON response... # Use the following online tool to generate parsing code from sample JSON: # Generate Parsing Code from JSON set date_gmt [new_CkDtObj] # json is a CkJsonObject set i 0 set count_i [CkJsonArray_get_Size $jarrResp] while {$i < $count_i} { set json [CkJsonArray_ObjectAt $jarrResp $i] set id [CkJsonObject_IntOf $json "id"] set date [CkJsonObject_stringOf $json "date"] CkJsonObject_DtOf $json "date_gmt" 0 $date_gmt set guidRendered [CkJsonObject_stringOf $json "guid.rendered"] set modified [CkJsonObject_stringOf $json "modified"] set modified_gmt [CkJsonObject_stringOf $json "modified_gmt"] set slug [CkJsonObject_stringOf $json "slug"] set status [CkJsonObject_stringOf $json "status"] set v_type [CkJsonObject_stringOf $json "type"] set link [CkJsonObject_stringOf $json "link"] set titleRendered [CkJsonObject_stringOf $json "title.rendered"] set contentRendered [CkJsonObject_stringOf $json "content.rendered"] set contentProtected [CkJsonObject_BoolOf $json "content.protected"] set excerptRendered [CkJsonObject_stringOf $json "excerpt.rendered"] set excerptProtected [CkJsonObject_BoolOf $json "excerpt.protected"] set author [CkJsonObject_IntOf $json "author"] set featured_media [CkJsonObject_IntOf $json "featured_media"] set comment_status [CkJsonObject_stringOf $json "comment_status"] set ping_status [CkJsonObject_stringOf $json "ping_status"] set sticky [CkJsonObject_BoolOf $json "sticky"] set template [CkJsonObject_stringOf $json "template"] set format [CkJsonObject_stringOf $json "format"] set j 0 set count_j [CkJsonObject_SizeOfArray $json "meta"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "categories"] while {$j < $count_j} { CkJsonObject_put_J $json $j set intVal [CkJsonObject_IntOf $json "categories[j]"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "tags"] while {$j < $count_j} { CkJsonObject_put_J $json $j set intVal [CkJsonObject_IntOf $json "tags[j]"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.self"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.self[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.collection"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.collection[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.about"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.about[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.author"] while {$j < $count_j} { CkJsonObject_put_J $json $j set embeddable [CkJsonObject_BoolOf $json "_links.author[j].embeddable"] set href [CkJsonObject_stringOf $json "_links.author[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.replies"] while {$j < $count_j} { CkJsonObject_put_J $json $j set embeddable [CkJsonObject_BoolOf $json "_links.replies[j].embeddable"] set href [CkJsonObject_stringOf $json "_links.replies[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.version-history"] while {$j < $count_j} { CkJsonObject_put_J $json $j set count [CkJsonObject_IntOf $json "_links.version-history[j].count"] set href [CkJsonObject_stringOf $json "_links.version-history[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.predecessor-version"] while {$j < $count_j} { CkJsonObject_put_J $json $j set id [CkJsonObject_IntOf $json "_links.predecessor-version[j].id"] set href [CkJsonObject_stringOf $json "_links.predecessor-version[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.wp:attachment"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.wp:attachment[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.wp:term"] while {$j < $count_j} { CkJsonObject_put_J $json $j set taxonomy [CkJsonObject_stringOf $json "_links.wp:term[j].taxonomy"] set embeddable [CkJsonObject_BoolOf $json "_links.wp:term[j].embeddable"] set href [CkJsonObject_stringOf $json "_links.wp:term[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.curies"] while {$j < $count_j} { CkJsonObject_put_J $json $j set name [CkJsonObject_stringOf $json "_links.curies[j].name"] set href [CkJsonObject_stringOf $json "_links.curies[j].href"] set templated [CkJsonObject_BoolOf $json "_links.curies[j].templated"] set j [expr $j + 1] } delete_CkJsonObject $json set i [expr $i + 1] } delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonArray $jarrResp delete_CkDtObj $date_gmt |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.