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
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
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.

Categories
Technology Web

The time is now 1997

Recovered from the Wayback Machine.

Back in 1996 and into 1997, frames were big, as was the use of HTML tables to organize a web page. The current look for this site was copied directly from backup files I had for 1996 through 1998. The links, if you try them, will open up various pages to example code, most of which hasn’t been touched in close to 8 years.

If you access a specific post, the page will open up my traditional look, primarily because this design from 1996 made use of frames, and frames play havoc with weblogging templates–the URI parameters don’t get passed to the each frame document. Just one of the many challenges we were faced with, daily, when designing web pages years ago. Back before XHTML and structured design; back before CSS had wide support; back even before Flash–when dynamic scripting was new and cross-browser development was an exhausting adventure into never-ever-again land.

From now through this weekend, I’m going to be revisiting much of my old, old content from the so-called Web 1.0 — revisiting it, republishing some of it, and writing on the state of the technology then and now. I’ll be putting up old designs and linking to associated pages in the Wayback Machine (such as Scenarios–check out the bottom of the pages), which demonstrate even more of the technology and philosophy that ruled the web then.

(I’ll be making screenshots of these pages for including when the design reverts back to the norm.)

For many of us, creating web pages and samples and bits of code to give away in the 1990’s was a true labor of love. We didn’t make any money, and didn’t really expect to; or to achieve any form of fame. We didn’t have ranking systems, comments, and such; the only feedback we had was when a person would send an email now and again and say thanks, or we’d see something we created in use elsewhere (and what a joy and thrill that was).

Back then, our pages were bright colors, because in prior years all the only color we had was white. We embedded images for anything because in prior years all we could add was text. And animated GIFs and BLINK weren’t the enemy the way they are now, because they were the first example of a living page.

All of this was new, and every month it seemed, some marvelous new technology would be released.

Welcome to the Web 1.0. Welcome to 1997. It was a good year.

Categories
Web

Sleeping around Web 2.0 Style

Recovered from the Wayback Machine.

thespecksvol1-1