Go
Go
WordPress Authentication with Applications Password Plugin
See more WordPress Examples
Demonstrates basic username/password authentication using the WordPress Applications Password plugin.Chilkat Go Downloads
success := false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := chilkat.NewHttp()
// 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.
http.SetLogin("wp_username")
// Use the application password, such as "Nths RwVH eDJ4 weNZ orMN jabq"
http.SetPassword("app_password")
http.SetBasicAuth(true)
sbResponseBody := chilkat.NewStringBuilder()
success = http.QuickGetSb("https://www.yoursite.com/wp-json/wp/v2/posts?page=1",sbResponseBody)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
return
}
jarrResp := chilkat.NewJsonArray()
jarrResp.LoadSb(sbResponseBody)
jarrResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jarrResp.Emit())
respStatusCode := http.LastStatus()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(http.LastHeader())
fmt.Println("Failed.")
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jarrResp.DisposeJsonArray()
return
}
// 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
date_gmt := chilkat.NewDtObj()
// json is a JsonObject
var id int
var date *string = new(string)
var guidRendered *string = new(string)
var modified *string = new(string)
var modified_gmt *string = new(string)
var slug *string = new(string)
var status *string = new(string)
var v_type *string = new(string)
var link *string = new(string)
var titleRendered *string = new(string)
var contentRendered *string = new(string)
var contentProtected bool
var excerptRendered *string = new(string)
var excerptProtected bool
var author int
var featured_media int
var comment_status *string = new(string)
var ping_status *string = new(string)
var sticky bool
var template *string = new(string)
var format *string = new(string)
var j int
var count_j int
var intVal int
var href *string = new(string)
var embeddable bool
var count int
var taxonomy *string = new(string)
var name *string = new(string)
var templated bool
i := 0
count_i := jarrResp.Size()
for i < count_i {
json := jarrResp.ObjectAt(i)
id = json.IntOf("id")
date = json.StringOf("date")
json.DtOf("date_gmt",false,date_gmt)
guidRendered = json.StringOf("guid.rendered")
modified = json.StringOf("modified")
modified_gmt = json.StringOf("modified_gmt")
slug = json.StringOf("slug")
status = json.StringOf("status")
v_type = json.StringOf("type")
link = json.StringOf("link")
titleRendered = json.StringOf("title.rendered")
contentRendered = json.StringOf("content.rendered")
contentProtected = json.BoolOf("content.protected")
excerptRendered = json.StringOf("excerpt.rendered")
excerptProtected = json.BoolOf("excerpt.protected")
author = json.IntOf("author")
featured_media = json.IntOf("featured_media")
comment_status = json.StringOf("comment_status")
ping_status = json.StringOf("ping_status")
sticky = json.BoolOf("sticky")
template = json.StringOf("template")
format = json.StringOf("format")
j = 0
count_j = json.SizeOfArray("meta")
for j < count_j {
json.SetJ(j)
j = j + 1
}
j = 0
count_j = json.SizeOfArray("categories")
for j < count_j {
json.SetJ(j)
intVal = json.IntOf("categories[j]")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("tags")
for j < count_j {
json.SetJ(j)
intVal = json.IntOf("tags[j]")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.self")
for j < count_j {
json.SetJ(j)
href = json.StringOf("_links.self[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.collection")
for j < count_j {
json.SetJ(j)
href = json.StringOf("_links.collection[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.about")
for j < count_j {
json.SetJ(j)
href = json.StringOf("_links.about[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.author")
for j < count_j {
json.SetJ(j)
embeddable = json.BoolOf("_links.author[j].embeddable")
href = json.StringOf("_links.author[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.replies")
for j < count_j {
json.SetJ(j)
embeddable = json.BoolOf("_links.replies[j].embeddable")
href = json.StringOf("_links.replies[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.version-history")
for j < count_j {
json.SetJ(j)
count = json.IntOf("_links.version-history[j].count")
href = json.StringOf("_links.version-history[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.predecessor-version")
for j < count_j {
json.SetJ(j)
id = json.IntOf("_links.predecessor-version[j].id")
href = json.StringOf("_links.predecessor-version[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.wp:attachment")
for j < count_j {
json.SetJ(j)
href = json.StringOf("_links.wp:attachment[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.wp:term")
for j < count_j {
json.SetJ(j)
taxonomy = json.StringOf("_links.wp:term[j].taxonomy")
embeddable = json.BoolOf("_links.wp:term[j].embeddable")
href = json.StringOf("_links.wp:term[j].href")
j = j + 1
}
j = 0
count_j = json.SizeOfArray("_links.curies")
for j < count_j {
json.SetJ(j)
name = json.StringOf("_links.curies[j].name")
href = json.StringOf("_links.curies[j].href")
templated = json.BoolOf("_links.curies[j].templated")
j = j + 1
}
json.DisposeJsonObject()
i = i + 1
}
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jarrResp.DisposeJsonArray()
date_gmt.DisposeDtObj()