Categories
Technology Web

Accessing the Newsgator API within PHP

One of the programming jobs I’ve had recently was to provide PHP functions to access the Newsgator SOAP API; hiding as much of the SOAP bits as possible. I used the nuSOAP PHP library as the basis for my work. Though SOAP functionality is built into PHP 5, my client, like most people, are still using PHP 4, and nuSOAP has a very clean implementation.

For those who might want to give the API a shot, I’ll walk through some sample code that should be easily modified as interested. I had hoped to write a more complete application, but have ran out of time.

The Newsgator API requires an account in order to test the code, but you can sign up for one at no charge. When you get an account, you’re given an online Newsgator Location in which to add subscriptions. You’re also given the ability to create new locations, as well as folders, and to subscribe to and read, syndication feeds. The API itself is split into five main categories for the five SOAP endpoints: Locations, Folders, Subscriptions, Feeds, and Posts.

Each SOAP engpoint page lists the web service methods for the specific item, including a description of the parameters and values returned. An important element when looking at the page is to find a link to the endpoint at the bottom. Clicking on it opens a window asking for the account username and password. Once you enter these, the endpoint page opens, containing links for each of the methods.

Clicking on a method link opens up another page, usually containing a form, and an example SOAP request and response. These latter are essential in order to determine the values used with nuSOAP. You can also test the web service by typing values into the form and invoking the method. If, that is, the parameters are simple values rather than programmatic structures, such as arrays.

Once you’ve looked through the API methods to see what parameters are needed, and explored the actual SOAP request and response, it’s just a matter of plugging in values within the nuSOAP functions. To demonstrate, I’m going to walk through a program that creates a SOAP client, queries the service for all subscriptions for a given location, and then accesses and prints out links to the individual items for the subscriptions.

In the program, I first create a SOAP client using the appropriate endpoint, checking for any error afterwards. (Complete source code is provided later, so no worries about any gaps in the code):

// create SOAP client
$client = new soapclient(”http://services.newsgator.com/ngws/svc/Subscription.asmx”);
$err = $client->getError();
if ($err) {
err($client,$err);
die();
}

I’m not using a proxy or WSDL, so no other parameters other than the endpoint are set.

Next, I define the method’s parameters, in this case a location string and a synchronization token. This latter value is used to synchronize the data between method calls, and in the results you’ll see this returned as part of the response. Using this provided synch value in the next method call ensures that the data, such as the count of unread items for each subscription, is fresh.

// set parameters
$params = array(
‘location’ => $location,
’syncToken’ => $synctoken
);

During the initial web service request, the synch token is blank.

Once the method parameters are set, I added code to authenticate the user:

// authenticate against the service
$client->setCredentials($user, $pass,’basic’);

Note that this uses example uses BASIC authentication; Newsgator also supports DIGEST authentication.

The Newsgator API token is passed in a SOAP header, which I build manually next. Note that the token must be authenticated with the service, so you’ll need to specify the appropriate service namespace:

// create SOAP header for Newsgator API
$hdr = “<ng:NGAPIToken xmlns:ng=’http://services.newsgator.com/svc/Subscription.asmx’>
<ng:Token>$token</ng:Token></ng:NGAPIToken>”;

Finally, we can now invoke the service:

// invoke SOAP service
$result = $client->call(’GetSubscriptionList’, $params,’http://services.newsgator.com/svc/Subscription.asmx’,
‘http://services.newsgator.com/svc/Subscription.asmx/GetSubscriptionList’,
$hdr,false, ‘rpc’,’literal’);

// check for error
if ($client->fault) {
echo ‘<h2>Fault</h2><pre>’; print_r($result); echo ‘</pre>’;
} else {
$err = $client->getError();
if ($err) {
echo ‘<h2>Error</h2><pre>’ . $err . ‘</pre>’;
}
}

In this function call, the SOAP method is the first parameter, followed by the parameters, the SOAP endpoint (namespace), the SOAP action, the manually created header, the serialization style (’rpc’), and the serialization for the parameters (’literal).

The nuSOAP function processes any XML returned as multi-dimensioned arrays. With this service call, the subscriptions are returned as OPML, values of which you can access by walking through the array:

// decipher the array, based on OPML
$opml = $result[”opml”];
$body = $opml[”body”];
$outline = $body[”outline”];
$syntoken = $opml[”!ng:token”];
foreach ($outline as $key => $sub) {
$feed = $sub[”!ng:id”];
$title = $sub[”!title”];
$url = $sub[”!htmlUrl”];
echo “<a href=’$url’>$title</a><br />”;
}

After each subscription is accessed, the feed identifier ($feed) is then used to invoke another service to get the news for the feed. The complete application demonstrates this.

Categories
RDF Technology

The Wordform/WordPress metaform

Time to start releasing some code.

The Metaform RDF extension and plugins are finally really for beta use.

The Metaform Extension creates a new page in your WordPress weblog that provides a home for all metadata extensions. You’ll also need to add a few lines to your wp-configure.php file and a couple of your templates. The install.txt file has installation instructions.

Included in the installation is a stripped down version of RAP: RDF API for PHP. This should work in PHP 4.3 and up, and will require no other external libraries.

The first plugin is the Links Plugin, which will parse out hypertext links in a post and store them as RDF data. This then can be used to add a link list to your syndication feed or your post, or however else you want to use the data. Again, follow the instructures in install.txt to use it.

I plan to finish packaging a few others for release tonight. My hope is, though, that the Metaform infrastructure will encourage a whole host of RDF-based plugins; using those I’ve created as templates and expanding in ways I haven’t imagined. Regardless, the extension and the plugins do demonstrate that RDF isn’t just for large, esoteric applications requiring a host of PhDs to create.

A few weeks ago the discussion about RDF focused on how complex it is, how hard it is to use; how difficult it is to use in hacking, or for creating simple applications. What Metaform demonstrates is that RDF can be hackable, simple, and immediately useful. It may not be as sexy as Web 2.0, but it is real.

The SeeAlso Plugin allows you to add one or more external references to a post, and have a list of these printed out in the page and/or syndicated feed. Follow the install.txt for how to install.

The Photo plugin accesses the Flickr API to gather metadata about a Flickr embedded photo in the post. The data is then output via a link, added by plugin.

A future version will have access to Google maps, and processing of XMP data.

Categories
Web

Please…do evil

Recovered from the Wayback Machine.

Google Blogoscoped Terms of Service:

By submitting, posting or displaying Content on or through Google services which are intended to be available to the general public, you grant Google a worldwide, non-exclusive, royalty-free license to reproduce, modify, adapt, publish and otherwise use, with or without attribution such Content on Google services solely for the purpose of displaying, distributing and promoting Google services.

Book review of Tom Sawyer by Sandi W. Age 9:

When Tom met Huck Finn and became friends, it reminded me of when I met my friend Seu Mei. We became best friends for a few years. Between those few years, we met more friends. My favorite part in the book was when Tome tricked his friend. His friend had to paint the fence white and Tom got to rest. I read another book by the same author. It is called Huckleberry Finn. I enjoy reading these books because I like to solve the mysteries.

The main point of view of Google Base is that this is going after eBay and Craigslist, and online classifieds. I would say the target is Wikipedia, too. Is this a dangerous move? Depends. Ask yourself the question: at what point can you afford to lose Google and still do business?

Categories
Connecting Technology Weblogging

Neighborly news

Recovered from the Wayback Machine.

If you haven’t had a chance to check out Jerry’s electric car weblog, give it a glance. In the weblog, Jerry is chronicling the process of converting a gas burning Ford Probe into a sleek, clean, electric car.

Jeneane was on the radio today talking about blogging. Nifty Jeneane. Now, we gotta get you off of Blogspot.

Sheila Lennon writes about Sinead O’Connor’s new reggae focused album. I really like reggae, and I appreciate O’Connor’s conversion to the Rastafarian belief, but what she sings is not reggae. It may be the words, it may be the notes, but it isn’t reggae.

Sheila also mentions that Carly Simon–the lady in the gauzy, see-through hippy dress who sang the weblogging anthem decades before weblogging itself was invented–has turned 60 and released a new album. It is also a disappointing bust. I like the type of music, but she doesn’t have the voice to do it justice.

Carly Simon. Brings back memories. Decades ago she was an earth child/sex kitten with a sultry, folksy voice–not an easy combo of image and tone. I remember once buying a see-through dark green patterned gauzy peasant blouse to wear, trying to capture a little of that Simon persona. Every boy I knew back in the early 70’s was in love with Carly Simon. Yup, many a boy fantasized over one or the other of her album covers.

Why, one such boy might have been Dave Rogers, who just returned from a class reunion. Dave points out a the new anti-tech column at Wired. In it, the author, Tony Long, writes:

Anything that diminishes the value of a single human being poses a threat to a rational, humane society. When technology can cure a disease or help you with your homework or bring a little joy to a shut-in, that’s great. But when it costs you your job, or trashes the environment, or takes you out of the real world in favor of a virtual one, or drives your blood pressure through the roof, it’s a monster.

I can agree with the author, but I’d have to add a caveat that it isn’t the technology or even the technologists who are the monster. Follow the promises scattered like so many broken bits of white plastic until you bump up against those with a gleam of silver and gold in their eyes if you want to see the many headed hydra of tech. Still, this promises to be a very interesting column–if only it had a syndication feed, so that I could read it on my computer while I’m at the coffee shop talking on my cell, all the while eying the freaky poet chick and thinking I should get a picture of her for my blog.

Speaking of local hangouts, Karl has written a thoughtful piece about his hangout at PhillyFuture and what he’d like to see in the future for the publication, but he can’t do it alone. Community sites need community.

Well, you do unless you have an aggregator. Oh, and comments. Trackbacks, too. Wait a sec–don’t forget the wiki. And you’re not hip if you don’t do OPML. By the way, is that iPod of yours really six months old? And it still works?

Categories
Web

Rosebud

Recovered from the Wayback Machine.

I didn’t know this post had actually published to my syndication feed until I spotted references to it in Bloglines. Since the URL is on permanent record now, I decided to provide something to fill the gap.

The best quote related to Web 2.0 comes from Nick Douglas at Blogebrity:

Web 2.0, says Jeff Jarvis, is made of people. As opposed to Web 1.0, which was made of spacer gifs.

Second best:

Like so many San Francisco buildings, it was old, and brick, and recently converted into brand-spanking-new office space. High ceilings and exposed beams and ductwork everywhere. An old black dog lifted its head off the floor next to the reception desk as I entered the roomy VC suite. He barked and grumbled. The receptionist was embarrassed and surprised the dog didn’t like me. I instantly liked the dog, but the feeling was not mutual. I kept my distance.

So I met with the VC. He just came on board at the firm; this was his second day. I already pitched to this firm 18 months earlier, at their old offices. He didn’t know that. Now he did. In those 18 months I’d raised an angel round and an “A” round from other VCs. While Jenny Ondioline played over and over in my head, we talked for a good while about my company and our plans. At the conclusion of the meeting we agreed to follow up in a month or so.

I wonder if the dog is their “invest” / “don’t invest” signal? If the dog excitedly wags his tail with the arrival of a visitor, give ‘em money. If the dog barks and growls, don’t. In a few months maybe I’ll know.

And his follow up is equally good.