Blogger/REBOL XML-RPC
[1/7] from: chaz:innocent at: 19-Aug-2001 3:45
I'm trying to get data from my blog (abbreviation for "web log") using
blogger's xml-rpc interface http://plant.blogger.com/api/
downloaded Christian Langreiter's RXR from http://www.langreiter.com/space/RXR
created a blog at http://www.blogger.com
got an application key here http://plant.blogger.com/api/register.html
Started happily coding in REBOL, unfortunately neither one of the functions
below work.
This function is supposed to contact the RPC server at blogger.com
I give it my application key, username, and password
and it will give me my blog's URL, blogid, and the blog's title.
If it fails, then it will type "Sorry, and error has occurred"
I'm trying to use the function
http://plant.blogger.com/api/xmlrpc_getUsersBlogs.html
REBOL [Title: "getUsersBlogs via XML-RPC"]
do load %xmlrpc-lib.r
plant: make xmlrpc-server [host: "plant.blogger.com" port: 80 uri:
/api/RPC2
]
states: xmlrpc-struct
states/data: ["your application key" "your username" "your password"]
view layout [
t-rs: field "Result"
b-do: button "Get" [
if error? try [
t-rs/text: xmlrpc-call plant "blogger.getUsersBlogs"
[states]
] [
t-rs/text: "Sorry, an error has occured!"
]
show t-rs
]
]
This function is supposed to contact the RPC server at blogger.com
I give it my application key, blogid, username, password, message test, and
whether or not I was to publish my post.
and it will give me my post's ID
If it fails, then it will type "Sorry, and error has occurred"
I'm trying to use the function
http://plant.blogger.com/api/xmlrpc_newPost.html
REBOL [Title: "newPost via XML-RPC"]
do load %xmlrpc-lib.r
plant: make xmlrpc-server [host: "plant.blogger.com" port: 80 uri:
/api/RPC2
]
states: xmlrpc-struct
states/data: ["<application key>" "<blogid>" "<username>" "<password>"
Hello World
false]
view layout [
t-rs: field "Result"
b-do: button "Get" [
if error? try [
xmlrpc-call plant "blogger.newPost" [states]
] [
t-rs/text: "Sorry, an error has occured!"
]
show t-rs
]
]
[2/7] from: dave:jtgoodstuff at: 19-Aug-2001 9:09
Can you trap exactly what you are sending, headers and all, and post what
you are sending?
[3/7] from: chaz:innocent at: 19-Aug-2001 10:31
>Can you trap exactly what you are sending, headers and all, and post what
>you are sending?
That sounds like a reasonable request, however, at this moment, I'm not
sure how to do that.
Below is a document by the creator of the API.
Maybe a more basic question is "how do I send and receive these xml
messages using REBOL?"
http://plant.blogger.com/api/xmlrpc_getUsersBlogs.html
blogger.getUsersBlogs via XML-RPC
By Evan Williams, 8/13/01
blogger.getUsersBlogs returns information about all the blogs a given user
is a member of. Data is returned as an array of <struct>'s containing the
ID (blogid), name (blogName), and URL (url) of each blog.
URI
All XML-RPC requests should go to the following URI:
http://plant.blogger.com/api/RPC2
Note: This could (and, likely, will) change at some point! (Due warning
will be given.)
Parameters
blogger.getUsersBlogs takes the following parameters. All are required:
appkey (string): Unique identifier/passcode of the application sending the
post. (See access info.)
username (string): Login for the Blogger user who's blogs will be retrieved.
password (string): Password for said username.
Examples
Here is an example of an XML-RPC call to blogger.getUsersBlogs:
POST /api/RPC2 HTTP/1.0
User-Agent: Java.Net Wa-Wa 2.0
Host: plant.blogger.com
Content-Type: text/xml
Content-length: 515
<?xml version="1.0"?>
<methodCall>
<methodName>blogger.getUsersBlogs</methodName>
<params>
<param><value><string>C6CE3FFB3174106584CBB250C0B0519BF4E294</string></value
></param>
<param><value><string>ewilliams</string></value></param>
<param><value><string>secret</string></value></param>
</params>
</methodCall>
Here is an example methodResponse with no errors:
HTTP/1.1 200 OK
Connection: close
Content-Length: 125
Content-Type: text/xml
Date: Mon, 6 Aug 20001 19:55:08 GMT
Server: Java.Net Wa-Wa/Linux
<?xml version="1.0" encoding="ISO-8859-1"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>url</name>
<value>http://stuff.foo.com/biz</value>
</member>
<member>
<name>blogid</name>
<value>2997323</value>
</member>
<member>
<name>blogName</name>
<value>Blogger Biz Dev</value>
</member>
</struct>
</value>
<value>
<struct>
<member>
<name>url</name>
<value>http://www.blogger.com/</value>
</member>
<member>
<name>blogid</name>
<value>2723</value>
</member>
<member>
<name>blogName</name>
<value>Blogger News</value>
</member>
</struct>
<value>
<struct>
<member>
<name>url</name>
<value>http://www.geocities.com/rafting/</value>
</member>
<member>
<name>blogid</name>
<value>223723</value>
</member>
<member>
<name>blogName</name>
<value>RaftingBlog</value>
</member>
</struct>
</value>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
Errors
Errors are returned as an XML-RPC <methodResponse> with a <fault> item,
containing a <struct> with a faultCode and a faultString, as defined by the
XML-RPC spec.
Here an example response for an unsuccessful post. This error is due to a
bad username/password combo:
HTTP/1.1 200 OK
Connection: close
Content-Length: 225
Content-Type: text/xml
Date: Mon, 6 Aug 20001 19:55:08 GMT
Server: Java.Net Wa-Wa/Linux
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>4</int></value>
</member>
<member>
<name>faultString</name>
<value><string>java.lang.Exception: java.lang.Exception:
Error: User
authentication failed: ewilliams</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>
At 09:09 AM 8/19/01 -0500, you wrote:
[4/7] from: chaz::innocent::com at: 19-Aug-2001 23:17
ok! I changed the line
plant: make xmlrpc-server [host: "plant.blogger.com" port: 80 uri:"/api/RPC2"]
to
plant: make xmlrpc-server [host: <my ip address> port: 80 uri:""]
I ran webserver.r in a different REBOL window and I got these headers
POST HTTP/1.0
User-Agent: synerge REBOL/XML-RPC 0.3.0
Host: <my ip address>
Content-Type: text/xml
Content-Length: 328
Address: <my ip address>
Still trying to figure out how to display those 328 characters.
At 09:09 AM 8/19/01 -0500, you wrote:
[5/7] from: chaz:innocent at: 20-Aug-2001 0:35
Dude! this is great!
In the source for RXR there's a function, which, if you modify to this
xmlrpc-encode-struct: func [value [object!] /local res data tmp-blk] [
res: make string! 8000
data: value/data
append res "<value><struct>^/"
forskip data 2 [ ; [print reduce ["SNAME:" data/1 "SVALUE:" data/2]]
append res "<param>^/" ;to go back, comment this line, uncomment the next 4
; append res "<member>^/" ; original
; append res "<name>" ;
original
; append res data/1 ; original
; append res "</name>^/"
; original
tmp-blk: make block! 1
insert tmp-blk data/2
append
res xmlrpc-encode tmp-blk 'struct
append res "</param>^/" ; to go back
comment this line, uncomment the next 1
; append res "</member>^/" ;
original
]
append res "</struct></value>"
return res
]
and you send a message like this
REBOL [Title: "getUsersBlogs via XML-RPC"]
do load %xmlrpc-lib.r
plant: make xmlrpc-server [host: "plant.blogger.com" port: 80 uri:
/api/RPC2
]
states: xmlrpc-struct
states/data: ["" "your application key" "" "your username" "" "your
password"]
view layout [
t-rs: field "Result"
b-do: button "Get" [
if error? try
t-rs/text: xmlrpc-call plant "blogger.getUsersBlogs"
[states]
] [
t-rs/text: "Sorry, an error has occured!"
]
show t-rs
]
]
you get "xmlrpc-fault 0 none" as a result. This is not the name of my blog,
yet this is very encouraging! This looks like the right direction to go!
At 09:09 AM 8/19/01 -0500, you wrote:
[6/7] from: chris:langreiter at: 20-Aug-2001 12:03
Ouch!
What's wrong is how you're passing the parameters.
Just do it this way:
xmlrpc-call pant "blogger.newPost" ["appkey" "blog-id" "user" "pass"
your-message
true]
xmlrpc-call plant "blogger.getUsersBlogs" ["appkey" "user" "pass"]
BTW, I've played with the XML-RPC API a bit and added blogging
capabilities to a Jabber bot of mine:
http://www.langreiter.com/space/jabber-blog-it
If you want to push REBOL a bit into the Blogger's spotlights, write a
/View app à la blogBuddy [1] and tell [ev--pyra--com] and [dave--userland--com]
about it ;-)
Have fun,
Chris
[1] http://www.hi.is/~sigfuso/blogbuddy/
[7/7] from: chaz:innocent at: 20-Aug-2001 23:56
Sorry for abusing your code. RXR is working much better, now that I'm using
it correctly!
I've implemented two functions in REBOL, more to come later.
REBOL [Title: "Blogger via XML-RPC"]
do load %xmlrpc-lib.r
plant: make xmlrpc-server [host: "plant.blogger.com" uri:"/api/RPC2"]
editblock: ["appkey" "blogid" "username" "password" "text text text " false]
checkblock: ["appkey" "username" "password"]
blogging: [if error? try [
editblock/5: t-edit/text
t-result/text: xmlrpc-call plant "blogger.newPost" editblock
][
t-result/text: "omg, something is terribly terribly wrong!"
]
show t-result
]
view layout[
t-edit: field "blog entry"
t-result: field "result"
b-post: button "post!" [
editblock/6: false
do blogging
]
b-publish: button "publish!" [
editblock/6: true
do blogging
]
b-getinfo: button "get info!" [
if error? try [
t-result/text: xmlrpc-call plant "blogger.getUsersBlogs"
checkblock
][
t-result/text: "omg, something is terribly terribly wrong!"
]
show t-result
]
]
At 12:03 PM 8/20/01 +0200, you wrote: