XML-RPC API: metaWeblog.newPost, no publish/draft/future capability

[If you don't know what the XML-RPC API is or don't care, please skip to the next or previous post]

As described here, the "metaWeblog.newPost" method "creates a new post, and optionally publishes it." It takes these parameters:

String blogid, String username, String password, struct content, boolean publish

The publish parameter doesn't do what you think it does. You can't use it to set a post's status to draft versus to publish. That issue is described here, complete with a workaround.

However, that workaround still won't let you create posts with a status of "future." For that, keep reading...

I wanted to set the status of entries to "future", and NoPublishMeansDraft doesn't help with that.

What I ended up doing is using my imperfect knowledge of Perl to edit [MT install directory]/lib/MT/XMLRPCServer.pm

In version 1.31 of that file (for MT 3.121), I inserted the following at line 165 in the newPost function:

## Java-like Perl courtesy of
## BigMediaBlog.com / Lonewacko.com
if ( defined $item->{mt_entry_status} ) {
my $statusString = $item->{mt_entry_status};
my $status = MT::Entry::status_int( $statusString )
or die MT::XMLRPCServer::_fault( "Value for mt_entry_status undefined (was '$statusString')" );
$entry->status( $status );
}

That should be inserted right after the following:

if ($mt->{cfg}->NoPublishMeansDraft) {
$entry->status($publish ? MT::Entry::RELEASE() : MT::Entry::HOLD());
} else {
$entry->status(MT::Entry::RELEASE());
}

I write Java, so there might be problems with that Perl or it might be possible to make it a one-liner. However, it seems to work. Sample code to use this:

import org.apache.xmlrpc.*;
import java.util.*;
// etc....
XmlRpcClient xmlrpc = new XmlRpcClient( "http://example.com/cgi-bin/mt/mt-xmlrpc.cgi" );
params = new Vector();
params.add( "1" ); // your blog ID
params.add( "[*YOUR LOGIN NAME*]" );
params.add( "[*YOUR PASSWORD*]" );
hashtable = new Hashtable();
hashtable.put( "title", "TITLE" );
hashtable.put( "description", "ENTRY TEXT" );
hashtable.put( "dateCreated", "20041126T05:43:43" );
// mt_entry_status can be "draft", "future", "publish", or "review"
// if mt_entry_status is not given, the NoPublishMeansDraft controls
// as described here:
// http://www.jayallen.org/journey/2003/10/tip_xmlrpc_and_movable_type
// if mt_entry status is not one of the allowed values, a fault is sent back
hashtable.put( "mt_entry_status", "future" );
params.add( hashtable );
// the publish parameter;
// actually whether to rebuild the post or not; see also the link above
params.add( new Boolean( false ) );
String postID = (String) xmlrpc.execute( "metaWeblog.newPost", params );

Bloggage · Fri, 11/26/2004 - 12:56 · · Importance: 1


Independent, in-depth coverage of immigration, politics, and media bias since 2002. Also: multiculturalism, Los Angeles, California, privacy, and occasionally celebrities and wacky humor...


If you can't find what you're looking for, see the About page or use the navigation features to the right.

Start here
Previous/Next
Diversions

Main

Atom feed · RSS 2.0 feed · RSS 0.91 feed · WML

Subscribe with Bloglines
Add to My Yahoo!
Add to My MSN
Please subscribe to the feed and tell your friends about this site.

Tag search
Full text search
Reliable, pre-11/19/08 only:

What's Hot

  • Can you make a phone call? Get the answers to the questions in the FAX here.
  • See the top posts in the last 45 days.
Navigation
All Tags
Note: only a fraction of the content has so far been tagged.
Site search (new window)
Custom Search

Categories
Archives

All Posts(links to each post by title)

Latest