PowerBuilder
PowerBuilder
WordPress Basic Authentication with miniOrange Plugin
See more WordPress Examples
Demonstrates basic username/password authentication using the miniOrange API Authentication plugin.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JarrResp
integer li_RespStatusCode
oleobject loo_Date_gmt
oleobject loo_Json
integer li_Id
string ls_Date
string ls_GuidRendered
string ls_Modified
string ls_Modified_gmt
string ls_Slug
string ls_Status
string ls_V_type
string ls_Link
string ls_TitleRendered
string ls_ContentRendered
integer li_ContentProtected
string ls_ExcerptRendered
integer li_ExcerptProtected
integer li_Author
integer li_Featured_media
string ls_Comment_status
string ls_Ping_status
integer li_Sticky
string ls_Template
string ls_Format
integer j
integer li_Count_j
integer li_IntVal
string ls_Href
integer li_Embeddable
integer li_Count
string ls_Taxonomy
string ls_Name
integer li_Templated
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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
loo_Http.Login = "wp_username"
loo_Http.Password = "wp_password"
loo_Http.BasicAuth = 1
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1",loo_SbResponseBody)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_SbResponseBody
return
end if
loo_JarrResp = create oleobject
li_rc = loo_JarrResp.ConnectToNewObject("Chilkat.JsonArray")
loo_JarrResp.LoadSb(loo_SbResponseBody)
loo_JarrResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JarrResp.Emit()
li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Http.LastHeader
Write-Debug "Failed."
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JarrResp
return
end if
// 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
loo_Date_gmt = create oleobject
li_rc = loo_Date_gmt.ConnectToNewObject("Chilkat.DtObj")
i = 0
li_Count_i = loo_JarrResp.Size
do while i < li_Count_i
loo_Json = loo_JarrResp.ObjectAt(i)
li_Id = loo_Json.IntOf("id")
ls_Date = loo_Json.StringOf("date")
loo_Json.DtOf("date_gmt",0,loo_Date_gmt)
ls_GuidRendered = loo_Json.StringOf("guid.rendered")
ls_Modified = loo_Json.StringOf("modified")
ls_Modified_gmt = loo_Json.StringOf("modified_gmt")
ls_Slug = loo_Json.StringOf("slug")
ls_Status = loo_Json.StringOf("status")
ls_V_type = loo_Json.StringOf("type")
ls_Link = loo_Json.StringOf("link")
ls_TitleRendered = loo_Json.StringOf("title.rendered")
ls_ContentRendered = loo_Json.StringOf("content.rendered")
li_ContentProtected = loo_Json.BoolOf("content.protected")
ls_ExcerptRendered = loo_Json.StringOf("excerpt.rendered")
li_ExcerptProtected = loo_Json.BoolOf("excerpt.protected")
li_Author = loo_Json.IntOf("author")
li_Featured_media = loo_Json.IntOf("featured_media")
ls_Comment_status = loo_Json.StringOf("comment_status")
ls_Ping_status = loo_Json.StringOf("ping_status")
li_Sticky = loo_Json.BoolOf("sticky")
ls_Template = loo_Json.StringOf("template")
ls_Format = loo_Json.StringOf("format")
j = 0
li_Count_j = loo_Json.SizeOfArray("meta")
do while j < li_Count_j
loo_Json.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("categories")
do while j < li_Count_j
loo_Json.J = j
li_IntVal = loo_Json.IntOf("categories[j]")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("tags")
do while j < li_Count_j
loo_Json.J = j
li_IntVal = loo_Json.IntOf("tags[j]")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.self")
do while j < li_Count_j
loo_Json.J = j
ls_Href = loo_Json.StringOf("_links.self[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.collection")
do while j < li_Count_j
loo_Json.J = j
ls_Href = loo_Json.StringOf("_links.collection[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.about")
do while j < li_Count_j
loo_Json.J = j
ls_Href = loo_Json.StringOf("_links.about[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.author")
do while j < li_Count_j
loo_Json.J = j
li_Embeddable = loo_Json.BoolOf("_links.author[j].embeddable")
ls_Href = loo_Json.StringOf("_links.author[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.replies")
do while j < li_Count_j
loo_Json.J = j
li_Embeddable = loo_Json.BoolOf("_links.replies[j].embeddable")
ls_Href = loo_Json.StringOf("_links.replies[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.version-history")
do while j < li_Count_j
loo_Json.J = j
li_Count = loo_Json.IntOf("_links.version-history[j].count")
ls_Href = loo_Json.StringOf("_links.version-history[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.predecessor-version")
do while j < li_Count_j
loo_Json.J = j
li_Id = loo_Json.IntOf("_links.predecessor-version[j].id")
ls_Href = loo_Json.StringOf("_links.predecessor-version[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.wp:attachment")
do while j < li_Count_j
loo_Json.J = j
ls_Href = loo_Json.StringOf("_links.wp:attachment[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.wp:term")
do while j < li_Count_j
loo_Json.J = j
ls_Taxonomy = loo_Json.StringOf("_links.wp:term[j].taxonomy")
li_Embeddable = loo_Json.BoolOf("_links.wp:term[j].embeddable")
ls_Href = loo_Json.StringOf("_links.wp:term[j].href")
j = j + 1
loop
j = 0
li_Count_j = loo_Json.SizeOfArray("_links.curies")
do while j < li_Count_j
loo_Json.J = j
ls_Name = loo_Json.StringOf("_links.curies[j].name")
ls_Href = loo_Json.StringOf("_links.curies[j].href")
li_Templated = loo_Json.BoolOf("_links.curies[j].templated")
j = j + 1
loop
destroy loo_Json
i = i + 1
loop
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JarrResp
destroy loo_Date_gmt