Basic Example II, vba wordpress remote control, demo.ayHello is fun but quite useless, so let’s proceed to wp.getUsersBlogs.
I make a table in access (id, isAdmin, blogid, url, blogName, xmlrpc) and then query wordpress, parse the xml response in store it in the database.
So here we go query WordPress :
-
methodname = "wp.getUsersBlogs"
-
-
'xmlrpc url
-
txtURL = "http://www.blog.com/xmlrpc.php"
-
-
'authorization
-
txtUserName = "user"
-
txtPassword = "pass"
-
-
'XML http request
-
Dim objSvrHTTP As ServerXMLHTTP
-
Dim strT As String
-
Set objSvrHTTP = New ServerXMLHTTP
-
-
objSvrHTTP.Open "POST", txtURL, False, CStr(txtUserName), _
-
CStr(txtPassword)
-
-
objSvrHTTP.setRequestHeader "Accept", "application/xml"
-
objSvrHTTP.setRequestHeader "Content-Type", "application/xml"
-
-
'here is the bit with the wp.getUserBlogs methodname,
-
'and the username and password
-
strT = ""
-
strT = strT & "<methodcall>"
-
strT = strT & "<methodname>" & methodname & "</methodname>"
-
strT = strT & "<params>"
-
strT = strT & "<param><value><string>" & txtUserName & "</string></value></param>"
-
strT = strT & "<param><value><string>" & txtPassword & "</string></value></param>"
-
strT = strT & "</params>"
-
strT = strT & "</methodcall>"
-
-
objSvrHTTP.send strT
that’s pretty straight forward.
I get an xml message back with the data stored in an array of STRUCT types.
-
'Create the DomDocument Object
-
Dim oDoc As MSXML2.DOMDocument
-
Set oDoc = CreateObject("MSXML2.DOMDocument")
-
oDoc.async = False
-
oDoc.validateOnParse = False
-
-
'Load the response in the DomDocument Object
-
Dim fSuccess As Boolean
-
fSuccess = oDoc.loadXML(objSvrHTTP.responseText)
-
If Not fSuccess Then
-
MsgBox "failed"
-
Exit Function
-
End If
-
-
'counters
-
ct = 1
-
cs = 1
-
-
'array to story the field values
-
Dim SArray(1 To 5) As String
-
-
'open the table as recordset
-
Dim d As DAO.Recordset
-
Set d = CurrentDb.OpenRecordset("blogs", dbOpenTable)
-
-
'lets get the structs
-
Set oChildren = oDoc.selectNodes("//struct")
-
For Each oStruct In oChildren
-
-
'the struct has members,
-
-
Set Members = oStruct.childNodes
-
For Each Member In Members
-
-
'each member has a param pair (field, value)
-
'skip the first param, and store the field value
-
'in an array
-
-
Set Params = Member.childNodes
-
For Each Param In Params
-
ct = ct + 1
-
If ct / 2 <> Int(ct / 2) Then
-
SArray(ct / 2) = Param.Text
-
cs = cs + 1
-
End If
-
Next
-
-
Next
-
-
'we got the struct data,
-
'now add the array to the database
-
-
With d
-
.AddNew
-
!isAdmin = SArray(1)
-
!url = SArray(2)
-
!blogid = SArray(3)
-
!blogName = SArray(4)
-
!xmlrpc = SArray(5)
-
.Update
-
End With
-
-
Next
-
-
'close up shop
-
d.Close
-
Set d = Nothing
-
-
End Function
The other worpdress api calls work quite the same.