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(””);
$err = $client->getError();
if ($err) {

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=’’>

Finally, we can now invoke the service:

// invoke SOAP service
$result = $client->call(’GetSubscriptionList’, $params,’’,
$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.


Truth hurts

Recovered from the Wayback Machine.

There are a lot of people upset at a Forbes Magazine cover story on weblogs (free and easy registration required). Of course, it seeks to generate heat by the lead-in, which is inflammatory to say the least:

Web logs are the prized platform of an online lynch mob spouting liberty but spewing lies, libel and invective. Their potent allies in this pursuit include Google and Yahoo.

Oddly enough, this statement could be something found in weblogs, where broad strokes of the brush are used to define any number of subjects. However, as we all know, weblogs are many things, and sometimes they’re full of lies pretending to be truth; other times they’re truth pretending to be lies.

According to the article:

But if blogging is journalism, then some of its practitioners seem to have learned the trade from Jayson Blair. Many repeat things without bothering to check on whether they are true, a penchant political operatives have been quick to exploit. “Campaigns understand that there are some stories that regular reporters won’t print. So they’ll give those stories to the blogs,” says Christian Grantham, a Democratic consultant in Washington who also blogs. He cites the phony John Kerry/secret girlfriend story spread by bloggers in the 2004 primaries. The story was bogus, but no blogger got fired for printing the lie. “It’s not like journalism, where your reputation is ruined if you get something wrong. In the blogosphere people just move on. It’s scurrilous,” Grantham says.

And though they have First Amendment protection and posture as patriotic muckrakers in the solemn pursuit of truth, the blog mob isn’t democratic at all. They are inclined to crush dissent with the “delete” key. When consultant Nick Wreden criticized credit card banking giant MBNA on his blog, a reader responded in support of MBNA. Wreden zapped the comment. “I just thought: ‘This has to be a plant,’” he says.

Where is the lie in this? I have seen, time and again, webloggers repeat even the most unbelievable stories as truth; and they do so without batting an eye. As for our ‘openness’ — I don’t think we have to go back over five plus years of discussing how disagreement is ignored, and links are used as rewards for the faithful to provide proof of this allegation. The very fact that I can agree with certain points in the Forbes article will almost guarantee that none of the outraged pundits will acknowledge that this post, and my contrarian viewpoint, exist.

Regardless, many webloggers do have unwritten agendas when they write on particular issues, people, and organizations. Many webloggers do stretch the truth and accuse without facts. Many webloggers do have an interest in causing harm, and don’t accept accountability for their actions.

Let’s be honest: webloggers can be evil–just like everyone else. Am I concerned about being lumped in with the “Do no Good” webloggers? Not a bit–my writing is here to read, and will either stand, or fall, on it’s own. If I don’t go around telling people I’m a weblogger, it’s not because of the article; I didn’t go around telling people I was a weblogger before it was published.

(I’m personally thinking of printing up “Member of the Burningbird Weblogging Mob” t-shirts. Anyone want to be a Burningbird Weblogging Mob Member? We’ll have a secret handshake, magic decoder ring, and rituals where we howl at the moon, while sticking pins into iVoodoos, the new Apple product– complete with easily scratchable surface, by design.)

As for the overall condemning nature of the article–it got attention, didn’t it?

What I don’t understand is why the pundits think this article is harmful. Forbes has issued a wakeup call that will make companies pay attention to weblogs in a way that all of the “markets are conversation” cheerleading hasn’t been able to accomplish. We wanted them to pay attention to us; now they are.

All in all, I found the article to be an entertaining read.

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.

Diversity Writing

The Testosterone Meme

Recovered from the Wayback Machine.

After checking out the web site for a few weeks now I’ve made several observations:

First, most of the stories covered are about business, rather than technology. The companies in focus may be technical, but the stories are about commerce.

Second, if you’re a woman writing about technology, don’t expect to show up in the site; when you do, expect to see your weblog disappear from view quickly. This site is for the big boys only.

Third, quiet uses of technology, such as discussions of .NET, digital identity, and others do not show in the list. If you want to appear, link an A-lister who is talking about Web 2.o or search (i.e. Google, Yahoo, or Microsoft). Actual discussions about technology fly under this ‘technology’ aggregator.

Fourth, rank matters more than content. Recently Danny Ayers started a conversation about what other options do we see for a semantic web. He got several responses — not an avalance, but respectable. However, Danny’s post and the cross-blog discussion didn’t show on What did show was a post by David Weinberger saying how he hadn’t posted in four days.

Conclusion: if this site represents the new Web 2.0 technologies that filter content to eliminate noise, then thee and me are nothing but static, baby.


Babble Meadow

Recovered from the Wayback Machine.

My train leaves in about 8 hours and I’m not going to try to nap before taking it. Instead, I’m going to write, about this and that, until I have to close my computer and pack it.

My mother did order DSL through her phone company for me to use because she didn’t want me to be cut off from work while I was in Sandpoint. It’s uncertain if it will work on her wires, and if it doesn’t we might try cable. Regardless, my time is going to be occupied with other things for a time, so these rambling weblog posts might be the last you’ll hear from me for a while. Perhaps when I return, I’ll have wonderous photos of the Snake River and other points to show; a nice change from Missouri.

I’ve tweaked the looks on the site, just enough to refine the header, resize the content and so on. I rather like the header, though I am using a transparent PNG image, which means that it looks solid white in IE. I’ve decided, though, that as long as the text is readable in IE I’ve met my obligations to that browser.

And I can’t even describe how much my back hurts. Luckily, the train seats are supposed to be fairly comfortable. And there is a lounge where one can get drinks. Alcohol does act as a muscle relaxant. I have a feeling though, the best pain killer will be vast vistas, and my camera.