Thursday, October 2, 2008

post photos from Nokia E71 to wordpress directly

That is what I initially wanted to do. But this is more about post images or videos to any service for that matter, from any Nokia phone that can run Share Online. But I've tried this for images only from my E71, using Share Online 3.0 to a PHP service.

One day I saw something funny on the road, drew my phone, took aim, and shot. And was inspired enough to want to set up a proper photoblog for candid shots, for all of half a day! But regardless of me eventually not putting up a photoblog, I decided to poke around to see if I could do this in principle. And here is the result of a day and a half of hacking about.

Share Online 3.0 comes pre-installed on the E71, but without Flickr as an option. Their FAQ pointed me to the configuration file to get Flickr in to SO. If you overlook the junk in it (that is the flickr icon, base64-encoded), it looks very simple. Publishing uses the Atom Post protocol and WSSE for authentication. Tweak the media_options section to add video/3gpp or video/mp4 if you like. Change the endpoint_path to your own service and point configure_file_URL back to this configuration file. And you're done.

Here's how my configuration file looked like: http://umangjaipuria.com/share/uj_configuration_file.cfg.
Copy the file over to your phone and open it. The E71 automatically recognized it as a Share Online service configuration and added "UJ" as a new service. Options -> Add new account on the phone will let you specify a username and password for the service.

Every request by Share Online to your service will have authentication requirements. There will be a HTTP_X_WSSE parameter in the http headers. It will look like this:
UsernameToken Username="user1", PasswordDigest="4bHGUQyK7n/2JtGo/Tbjsr0aFww=", Nonce="NrS4fnwVWDB5QiIVR0qtIQ==", Created="2008-10-02T06:30:33Z".
Parse the string to extract the various name/values pairs. WSSE authentication can be checked (PHP code here) with:
$mydigest = base64_encode(pack("H*",
sha1(base64_decode($nonce).$created.$correct_password)));

The string in $mydigest should be the same as the PasswordDigest field in the WSSE string.

The first time Share Online tries to get a list of actions possible with this service (the Update Service operation under Options). This is the only GET operation and thus, for all GET requests (upon successful authentication, of course) my service returns:
<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="service.post" href="http://myserver.com/nokia_shareonline.php" type="application/atom+xml" title="my photoblog">
<link rel="service.feed" href="http://myserver.com/feed/atom/" type="application/atom+xml" title="my photoblog">
<link rel="alternate" href="http://myserver.com/" type="text/html" title="my photoblog">
</feed>

With Content-Type set to application/atom+xml.
This tells Share Online where to make POST requests, amongst other things.

Now, about that POST request. Log the HTTP_RAW_POST_DATA to see what the request actually contains. The Atom protocol, again. But for some strange reason, Share Online makes two POST requests to submit a photo. The first one is just the image and in this case the post xml will have this element:
<standalone xmlns="http://sixapart.com/atom/typepad#">1</standalone>
The next one actually contains the description and the title and tags that you had entered in Share Online. I'm not sure how to correlate the two - I guess you have to assume that only one client (per authenticated user) is submitting at a time and sequential posts are related.

Since I saw the SixApart.com link above, I guess this is the exact Atom protocol Share Online uses: http://www.sixapart.com/developers/atom/protocol/.

This can be made into a nifty little Wordpress plugin. Perhaps some other day, if I decide to set up that photoblog after all.

So far, I'm loving my E71! If you have any cool tips or tricks to share about the phone, please leave me a comment. And check back again soon - I'm going to write about the apps I've set up on it.

4 comments:

Henri Vilminko said...

I was investigating the same thing (posting from Share Online to Wordpress) so thanks for the information! But does this really mean that the Atom functionality built into Wordpress can't handle the posts done by the SO client?

Umang said...

Omegas:
Sure it can. That is what I tried doing. A small plugin as a wrapper around this will help you control formatting etc of your posts through SO.

Henri Vilminko said...

I set up two scripts: shareconf.php which outputs the configuration file for Share Online and sharedserv.php which outputs the xml file containing the available services. SO is able to get and parse the configuration file but when trying to fetch the services I get a network error (404). I'm not even trying to use WSSE yet, just trying to make Share Online recognize my blog...

In your service configuration file you set the "service.post" link to "http://myserver.com/nokia_shareonline.php". Shouldn't it point to http://mysite.com/mywordpress/wp-app.php/posts or a similar URL?

Could you please email me the actual configuration files you used with your blog so I can stop banging my head against the wall? You can reach me at: omegas at gmail dot com

Umang said...

The URL doesn't really matter. It might have any handler behind it. For Wordpress, the URL that you describe seems about right.

I didn't hook it up with my blog eventually - just tried it with a plain php file on the server. Which means putting it inside Wordpress ought to be trivial.
So I'm afraid I can't send you the "actual files" that fit into Wordpress because I don't have any. :)

Let me see if I can find that php file...