Xbase++
Xbase++
WordPress Authentication with Applications Password Plugin
See more WordPress Examples
Demonstrates basic username/password authentication using the WordPress Applications Password plugin.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJarrResp
LOCAL nRespStatusCode
LOCAL oDate_gmt
LOCAL oJson
LOCAL nId
LOCAL cDate
LOCAL cGuidRendered
LOCAL cModified
LOCAL cModified_gmt
LOCAL cSlug
LOCAL cStatus
LOCAL cV_type
LOCAL cLink
LOCAL cTitleRendered
LOCAL cContentRendered
LOCAL nContentProtected
LOCAL cExcerptRendered
LOCAL nExcerptProtected
LOCAL nAuthor
LOCAL nFeatured_media
LOCAL cComment_status
LOCAL cPing_status
LOCAL nSticky
LOCAL cTemplate
LOCAL cFormat
LOCAL j
LOCAL nCount_j
LOCAL nIntVal
LOCAL cHref
LOCAL nEmbeddable
LOCAL nCount
LOCAL cTaxonomy
LOCAL cName
LOCAL nTemplated
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Implements the following CURL command:
// curl -X GET --user wp_username:app_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
// Use your WordPress login, such as "admin", not the application name.
oHttp:Login := "wp_username"
// Use the application password, such as "Nths RwVH eDJ4 weNZ orMN jabq"
oHttp:Password := "app_password"
oHttp:BasicAuth := 1
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJarrResp := CreateObject("Chilkat.JsonArray")
oJarrResp:LoadSb(oSbResponseBody)
oJarrResp:EmitCompact := 0
? "Response Body:"
? oJarrResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
RETURN
ENDIF
// 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
oDate_gmt := CreateObject("Chilkat.DtObj")
i := 0
nCount_i := oJarrResp:Size
DO WHILE i < nCount_i
oJson := oJarrResp:ObjectAt(i)
nId := oJson:IntOf("id")
cDate := oJson:StringOf("date")
oJson:DtOf("date_gmt", 0, oDate_gmt)
cGuidRendered := oJson:StringOf("guid.rendered")
cModified := oJson:StringOf("modified")
cModified_gmt := oJson:StringOf("modified_gmt")
cSlug := oJson:StringOf("slug")
cStatus := oJson:StringOf("status")
cV_type := oJson:StringOf("type")
cLink := oJson:StringOf("link")
cTitleRendered := oJson:StringOf("title.rendered")
cContentRendered := oJson:StringOf("content.rendered")
nContentProtected := oJson:BoolOf("content.protected")
cExcerptRendered := oJson:StringOf("excerpt.rendered")
nExcerptProtected := oJson:BoolOf("excerpt.protected")
nAuthor := oJson:IntOf("author")
nFeatured_media := oJson:IntOf("featured_media")
cComment_status := oJson:StringOf("comment_status")
cPing_status := oJson:StringOf("ping_status")
nSticky := oJson:BoolOf("sticky")
cTemplate := oJson:StringOf("template")
cFormat := oJson:StringOf("format")
j := 0
nCount_j := oJson:SizeOfArray("meta")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("categories")
DO WHILE j < nCount_j
oJson:J := j
nIntVal := oJson:IntOf("categories[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("tags")
DO WHILE j < nCount_j
oJson:J := j
nIntVal := oJson:IntOf("tags[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.self")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.self[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.collection")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.collection[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.about")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.about[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.author")
DO WHILE j < nCount_j
oJson:J := j
nEmbeddable := oJson:BoolOf("_links.author[j].embeddable")
cHref := oJson:StringOf("_links.author[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.replies")
DO WHILE j < nCount_j
oJson:J := j
nEmbeddable := oJson:BoolOf("_links.replies[j].embeddable")
cHref := oJson:StringOf("_links.replies[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.version-history")
DO WHILE j < nCount_j
oJson:J := j
nCount := oJson:IntOf("_links.version-history[j].count")
cHref := oJson:StringOf("_links.version-history[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.predecessor-version")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("_links.predecessor-version[j].id")
cHref := oJson:StringOf("_links.predecessor-version[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.wp:attachment")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.wp:attachment[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.wp:term")
DO WHILE j < nCount_j
oJson:J := j
cTaxonomy := oJson:StringOf("_links.wp:term[j].taxonomy")
nEmbeddable := oJson:BoolOf("_links.wp:term[j].embeddable")
cHref := oJson:StringOf("_links.wp:term[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.curies")
DO WHILE j < nCount_j
oJson:J := j
cName := oJson:StringOf("_links.curies[j].name")
cHref := oJson:StringOf("_links.curies[j].href")
nTemplated := oJson:BoolOf("_links.curies[j].templated")
j := j + 1
ENDDO
oJson:destroy()
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
oDate_gmt:destroy()