Sample code for 30+ languages & platforms
Visual FoxPro

WordPress API Key Authentication with miniOrange Plugin

See more WordPress Examples

Demonstrates API key authentication using the miniOrange API Authentication plugin.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loSbResponseBody
LOCAL loJarrResp
LOCAL lnRespStatusCode
LOCAL loDate_gmt
LOCAL loJson
LOCAL lnId
LOCAL lcDate
LOCAL lcGuidRendered
LOCAL lcModified
LOCAL lcModified_gmt
LOCAL lcSlug
LOCAL lcStatus
LOCAL lcV_type
LOCAL lcLink
LOCAL lcTitleRendered
LOCAL lcContentRendered
LOCAL lnContentProtected
LOCAL lcExcerptRendered
LOCAL lnExcerptProtected
LOCAL lnAuthor
LOCAL lnFeatured_media
LOCAL lcComment_status
LOCAL lcPing_status
LOCAL lnSticky
LOCAL lcTemplate
LOCAL lcFormat
LOCAL j
LOCAL lnCount_j
LOCAL lnIntVal
LOCAL lcHref
LOCAL lnEmbeddable
LOCAL lnCount
LOCAL lcTaxonomy
LOCAL lcName
LOCAL lnTemplated
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat.Http')

* Use your API key here, such as TaVFjSBu8IMR0MbvZNn7A6P04GXrbtHm
* This causes the "Authorization: Bearer <api_key>" header to be added to each HTTP request.
loHttp.AuthToken = "api_key"

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJarrResp = CreateObject('Chilkat.JsonArray')
loJarrResp.LoadSb(loSbResponseBody)
loJarrResp.EmitCompact = 0

? "Response Body:"
? loJarrResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJarrResp
    CANCEL
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

loDate_gmt = CreateObject('Chilkat.DtObj')

i = 0
lnCount_i = loJarrResp.Size
DO WHILE i < lnCount_i
    loJson = loJarrResp.ObjectAt(i)
    lnId = loJson.IntOf("id")
    lcDate = loJson.StringOf("date")
    loJson.DtOf("date_gmt",0,loDate_gmt)
    lcGuidRendered = loJson.StringOf("guid.rendered")
    lcModified = loJson.StringOf("modified")
    lcModified_gmt = loJson.StringOf("modified_gmt")
    lcSlug = loJson.StringOf("slug")
    lcStatus = loJson.StringOf("status")
    lcV_type = loJson.StringOf("type")
    lcLink = loJson.StringOf("link")
    lcTitleRendered = loJson.StringOf("title.rendered")
    lcContentRendered = loJson.StringOf("content.rendered")
    lnContentProtected = loJson.BoolOf("content.protected")
    lcExcerptRendered = loJson.StringOf("excerpt.rendered")
    lnExcerptProtected = loJson.BoolOf("excerpt.protected")
    lnAuthor = loJson.IntOf("author")
    lnFeatured_media = loJson.IntOf("featured_media")
    lcComment_status = loJson.StringOf("comment_status")
    lcPing_status = loJson.StringOf("ping_status")
    lnSticky = loJson.BoolOf("sticky")
    lcTemplate = loJson.StringOf("template")
    lcFormat = loJson.StringOf("format")
    j = 0
    lnCount_j = loJson.SizeOfArray("meta")
    DO WHILE j < lnCount_j
        loJson.J = j
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("categories")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnIntVal = loJson.IntOf("categories[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("tags")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnIntVal = loJson.IntOf("tags[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.self")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcHref = loJson.StringOf("_links.self[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.collection")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcHref = loJson.StringOf("_links.collection[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.about")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcHref = loJson.StringOf("_links.about[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.author")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnEmbeddable = loJson.BoolOf("_links.author[j].embeddable")
        lcHref = loJson.StringOf("_links.author[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.replies")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnEmbeddable = loJson.BoolOf("_links.replies[j].embeddable")
        lcHref = loJson.StringOf("_links.replies[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.version-history")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnCount = loJson.IntOf("_links.version-history[j].count")
        lcHref = loJson.StringOf("_links.version-history[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.predecessor-version")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnId = loJson.IntOf("_links.predecessor-version[j].id")
        lcHref = loJson.StringOf("_links.predecessor-version[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.wp:attachment")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcHref = loJson.StringOf("_links.wp:attachment[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.wp:term")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcTaxonomy = loJson.StringOf("_links.wp:term[j].taxonomy")
        lnEmbeddable = loJson.BoolOf("_links.wp:term[j].embeddable")
        lcHref = loJson.StringOf("_links.wp:term[j].href")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("_links.curies")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcName = loJson.StringOf("_links.curies[j].name")
        lcHref = loJson.StringOf("_links.curies[j].href")
        lnTemplated = loJson.BoolOf("_links.curies[j].templated")
        j = j + 1
    ENDDO
    RELEASE loJson
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJarrResp
RELEASE loDate_gmt