You should be automatically redirected . If not, visit
http://newlisper.wordpress.com
and update your bookmarks.

11/12/2005

Posting from newLISP

I'm using the post-url function in newLISP to post to this blog. Here's the function:

(define (make-new-post blog-id blog-username 
     blog-password post-title post-body)
    (write-buffer buffer  (string  (xml-parse 
    (post-url  "http://plant.blogger.com/api/RPC2"
    (format "
<?xml version=\"1.0\"?>
<methodCall>
    <methodName>
        blogger2.newPost
    </methodName>
    <params>
        <param>
        <value>
            <struct>
                <member>
                    <name>
                        username
                    </name>
                    <value>
                        <string>
                            %s
                        </string>
                    </value>
                </member>
                <member>
                    <name>
                        password
                    </name>
                    <value>
                        <string>
                            %s
                        </string>
                    </value>
                </member>
                <member>
                    <name>
                        appkey
                    </name>
                    <value>
                        <string>
                            1
                        </string>
                    </value>
                </member>
            </struct>
        </value>
        </param>
        <param>
        <value>
            <struct>
                <member>
                    <name>
                        blogID
                    </name>
                    <value>
                        <string>
                            %s
                        </string>
                    </value>
                </member>
                <member>
                    <name>
                        body
                    </name>
                    <value>
                        <string>
                            %s
                        </string>
                    </value>
                </member>
                <member>
                    <name>
                        title
                    </name>
                    <value>
                        <string>
                            %s
                        </string>
                    </value>
                </member>
                <member>
                    <name>
                        postOptions
                    </name>
                    <value>
                        <struct>
                            <member>
                                <name>
                                    title
                                </name>
                                <value>
                                    <string>
                                        %s
                                    </string>
                                </value>
                            </member>
                        </struct>
                    </value>
                </member>
            </struct>
        </value>
        </param>
        <param>
        <value>
            <struct>
                <member>
                    <name>
                        doPublish
                    </name>
                    <value>
                        <boolean>
                            1
                        </boolean>
                    </value>
                </member>
            </struct>
        </value>
        </param>
    </params>
</methodCall>
" blog-username blog-password blog-id 
  post-body post-title post-title) "" 10000 ) (+ 1 2 8)))))

and I call it like this:

(make-new-post blog-id blog-username 
              blog-password post-title post-body )

Nearly all of this is the XML request code. The xml-parse function reads the answer from Blogger and formats it for my benefit. If you use this code, reformat the XML to remove stray returns and tabs!

2 Comments:

At 20:18, Blogger don Lucio said...

I would delimit the long XML string in the (format ...) statement with [text]...[/text] tags. I think the XML coming close to 2048 characters the maximum for "..." quoted strings. If you do that, you also can omit the escape back-slash characters before quotes inside the string delimited with [text]...[/text] tags.

 
At 21:42, Blogger newlisper said...

Good idea. I keep forgetting about this (because it's not present in other languages I've used), but it's really handy to not have to escape quotes all the time!

Thanks!

 

Post a Comment

Links to this post:

Create a Link

<< Home