viernes, 12 de septiembre de 2014

Publicar en WordPress desde Microsoft Access via XMLRPC Parte 3

Esta es la tercera entrega de la saga que conecta al mundo Microsoft Access con WordPress. En esta oportunidad veremos como asociar una imagen destacada al artículo que estamos publicando en WordPress. Como siempre recomiendo leer en orden:
El código de la parte 3

Sub PublicarEnWordPress()
    ' Datos de Autenticación
    txtURL = SITIO
    txtUserName = USUARIO
    txtPassword = PASSWORD
    
    ' Datos del Post
    txtTitulo = "Hola mundo desde Access con imagen destacada"
    txtContenido = "Este es un post de ejemplo publicado desde Microsoft Access"
    Dim txtCategorias(1) As String
    txtCategorias(1) = "Uncategorized"
    txtImagen = "25"
      
    ' ServerXMLHTTP
    Dim objSvrHTTP As ServerXMLHTTP
    Dim strT As String
    Set objSvrHTTP = New ServerXMLHTTP
  
    ' Autenticación
    objSvrHTTP.Open "POST", txtURL, False, CStr(txtUsuario), CStr(txtPassword)
    objSvrHTTP.setRequestHeader "Accept", "application/xml"
    objSvrHTTP.setRequestHeader "Content-Type", "application/xml"

    strT = strT & "<methodCall>"
    
    ' Acción
    strT = strT & "<methodName>metaWeblog.newPost</methodName>"
    
    ' General
    strT = strT & "<params>"
    strT = strT & "<param><value><string>0</string></value></param>"
    strT = strT & "<param><value>" & txtUserName & "</value></param>"
    strT = strT & "<param><value><string>" & txtPassword & "</string></value></param>"
    strT = strT & "<param>"
    
    strT = strT & "<struct>"
    
    ' Categorías
    strT = strT & "<member><name>categories</name><value><array>"
    strT = strT & "<data>"
    
    For i = 1 To UBound(txtCategorias)
        strT = strT & "<value>" & txtCategorias(i) & "</value>"
    Next i
    strT = strT & "</data>"
    strT = strT & "</array></value></member>"
    
    ' Título, contenido y fecha
    strT = strT & "<member><name>description</name><value><![CDATA[" & txtContenido & "]]></value></member>"
    strT = strT & "<member><name>title</name><value>" & txtTitulo & "</value></member>"
    strT = strT & "<member><name>dateCreated</name><value><dateTime.iso8601>" & Format(Now(), "yyyyMMdd") & "T" & Format(Now(), "hh:mm:ss") & "</dateTime.iso8601></value></member>"
    
    ' Imagen destacada
    strT = strT & "<member><name>wp_post_thumbnail</name><value><![CDATA[" & txtImagen & "]]></value></member>"
    
    strT = strT & "</struct>"
    strT = strT & "</param>"
    
    ' Tipo de publicación: 0 DRAFT, 1 PUBLISH
    strT = strT & "<param><value><boolean>1</boolean></value></param>"
    strT = strT & "</params>"
    
    strT = strT & "</methodCall>"
    
    ' Publicación
    objSvrHTTP.send strT

    ' Debug
    Debug.Print objSvrHTTP.responseText
    MsgBox objSvrHTTP.responseText

End Sub


El resultado




Bibliografía



Hasta la próxima

No hay comentarios:

Publicar un comentario