Archive forCompanies

Google AJAX Feed API

Google has just launched their AJAX Feed API:

With the AJAX Feed API, you can download any public Atom or RSS feed using only JavaScript, so you can easily mash up feeds with your content and other APIs.

It requires JavaScript knowledge to integrate with any website, but it's all documented by Google and not hard to do.

Comments

Google AdSense API

Google has just opened for all developers their AdSense API introduced last year:

If you're a web developer or host, you may remember that we introduced you to the AdSense API last May. With the AdSense API, your users can create their own AdSense accounts on your site, and display ads alongside the content that they have created. They can also manage their accounts and view ad performance and earnings reports, all on your site.

Today, we're pleased to announce that the AdSense API is now open for all developers, with the release of our open development sandbox. This is a replica of the live service with some additional support to help you test and debug your applications. Once you implement the AdSense API in the development sandbox, we can go live with your implementation.

Using this API you can share advertising revenues with creating content online users without webnasters worrying too much about accounting and money, all managed by Google. It looks liek a win-win situation for everybody.

Some already fear that AdSense API will skyrocket click-fraud. However this is a sample account creatin using PHP straight from their online documentation:

<?php

// Copyright 2005, Google Inc. All rights reserved.

/**
 *  sample code to create an Adsense account through Adsense API
 */

require_once('lib/nusoap.php');
require_once('common.php');

$server = 'https://www.google.com';
$namespace = 'http://www.google.com/api/adsense/v2';

// Set up the authentication headers
$email = '<impl:developer_email>REPLACE WITH DEVELOPER EMAIL</impl:developer_email>';
$password = '<impl:developer_password>REPLACE WITH DEVELOPER PASSWORD</impl:developer_password>';
$client_id = '<impl:client_id>NOT RELEVANT</impl:client_id>';

$header = $email . $password . $client_id;

// creating soap client
$wsdl = $server . '/api/adsense/v2/AccountService?wsdl';
$client = new soapclient($wsdl, true);
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}
$client->soap_defencoding = 'UTF-8';

// Set the headers; they are needed for authentication
$client->setHeaders($header);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

// setting the parameter
$param = '<loginEmail>users_address_here@example.com</loginEmail>';
$param .= '<entityType>Individual</entityType>';
$param .= '<websiteUrl>http://test.aaa.com</websiteUrl>';
$param .= '<websiteLocale>en</websiteLocale>';
$param .= '<usersPreferredLocale>en_US</usersPreferredLocale>';
$param .= '<emailPromotionPreferences>true</emailPromotionPreferences>';
$param .= '<synServiceTypes>ContentAds</synServiceTypes>';
$param .= '<hasAcceptedTCs>true</hasAcceptedTCs>';
$param = '<createAdSenseAccount>' . $param . '</createAdSenseAccount>';

// invoke web service
showCall('createAdSenseAccount', $param);
$response = $client->call('createAdSenseAccount', $param, $namespace);
if ($client->fault) {
  showMyErrors($client);
  return;
}
$err = $client->getError();
if ($err) {
  showSoapClientError($err);
  return;
}

// get back the response
$response = $response['createAdSenseAccountReturn'];
showCreatedPublisher($response);

// showing the soap
showRequestResponse($client);

?>

Comments

Yahoo! Mail Web Service APIs

Yahoo! announced today availability for its Mail Web Service APIs:

With the Yahoo! Mail Web Service APIs, you can build applications to perform tasks such as listing messages, displaying folders, and composing and sending messages.

Here's an authentication example from their samples:

<?php
// test.php — Test Yahoo! Browser-Based Authentication
// A simple auth exmaple.
// Author: Jason Levitt
// Date: November 20th, 2006
// Version 1.0
//

// Edit these. Change the values to your Application ID and Secret
define("APPID", 'JzkILqzIkY1xxxxxxxxxIaGILaRWClvO');
define("SECRET", '10de7e35xxxxxxxxxe5749207495ed');

// Include the proper class file
$v = phpversion();
if ($v[0] == '4′) {
include("ybrowserauth.class.php4″);
} elseif ($v[0] == '5′) {
include("ybrowserauth.class.php5″);
} else {
die('Error: could not find the bbauth PHP class file.');
}

function CreateContent() {

$authObj = new YBrowserAuth(APPID, SECRET);

// If Yahoo! isn't sending the token, then we aren't coming back from an
// authentication attempt
if (empty($_GET["token"])) {
// You can send some data along with the authentication request
// In this case, the data is the string 'some_application_data'
echo 'You have not signed on using BBauth yet<br /><br />';
echo '<a href="'.$authObj->getAuthURL('some_application_data', true).'">Click here to authorize</a>';
return;
}

// Validate the sig
if ($authObj->validate_sig()) {
echo '<h2>BBauth authentication Successful</h2>';
echo '<h3>The user hash is: '.$authObj->userhash.'</h3>';
echo '<b>appdata value is:</b> '. $authObj->appdata . '<br />';
} else {
die('<h1>BBauth authentication Failed</h1> Possible error msg is in $sig_validation_error:<br />'. $authObj->sig_validation_error);
}

return;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8″ />
</head>
<body>
<div id="look">
<h2>Test BBauth </h2>
<div>
<?php CreateContent(); ?>
</div>
<div id="content">
</div>
</div>
</body>
</html>

They also offers $10 commission for developers which refer clients to premium Yahoo! Mail account.

Comments

How To Provide A Web API

I've just read an interesting post of Alex Boxworth called as mentioned: How To Provide A Web API. I totally agree with his view, just that I'd add:

- Document your Web API completly, with examples.
Different providers offers documentation in different forms, more or less complete. Web API consumers rnage from gurus to beginners, and I suppose you want your API used by as many people as possible. A structured, step by step instructions with samples will help a lot.

- Create code repository for scripts based on your web API.
There are many people capable of writing good code based on that API they may want to share with others, maye open-source. Why not create repositories for these small projects?

Comments

Blogger API Updated

I've just read about Blogger API updates you might be interested. Seems that they updated documentation and code samples, but also integration with other Google products, especially Calendar. Good to know.

Comments

Google Checkout API

As you already read in the news Google launched a few days ago Google Checkout, its online payment service. Dubbed 'GBuy' may be an alternative to EBay's PayPal (already eBay restricted Google Checkout as payment method on its auction site). One big minus is that is available only for US (for the moment, I hope).

I won't comment here too much about this new service, features or fees but mention new API. New Google Checkout API allows you a deep and secure integration with web/desktop apps. They offer samples for ASP (IIS), PHP & Java, with full documentation for each of these languages. Here's a link to PHP sample.

Files with their functions available for integration into your custom application are not trivial, but easy to understand. Give it a try and see if they are ok for your needs.

Comments

Google map geocoding

Google added a very useful functionality to their maps: geocoding

Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coodinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map based on street addresses in your database or addresses supplied by users. The Google Maps API includes a geocoder that can be accessed via HTTP request or directly from within the JavaScript. 

This was something I was looking for to have a complete solution for displaying & using maps.

Comments

Google Calendar API

Google has just released their web API for calendar (on Apr 20):

Google Calendar allows client applications to view and update calendar events in the form of Google data API ("GData") feeds. Your client application can use the Google Calendar data API to create new events, edit or delete existing events, and query for events that match particular criteria. 

There are a few steps to use Google Calendar, all described in their help files:

  • Create an account
  • Get magic cookie for your calendar, or feed URL (something like http://www.google.com/calendar/feeds/userID/private-magicCookie/full)
  • Request the feed, which returns a XML file;
  • Post back an event or comments with a XML file.

We'll be back shortly with a full featured example using PHP.

Comments

del.icio.us API

You know what del.icio.us is: a social bookmark service, now bought by Yahoo. You can create a free account and add your website bookmarks, even share with others.

They also released some API, but in my opinion very limited. All you can do is to manage your own bookmarks (links) with their tags and bundles. You can't do searches on popular websites and tags, or last added bookmarks.

To use it from any application or website you need a free account. All API help files are available at del.icio.us/help/api. They also provide HTML, RSS, JSON & JavaScript access (see help page).

The most important function (page), I think, is posts/add, which add a new link to your online account. You can do this operation from your browser openning

http://username:password@del.icio.us//api/posts/add?url=…&description=…URL title…&extended=…URL description…&tags=… tags…

 

You can create such a link even from JavaScript and call this page. One simple solution from JavaScript is to use new Image(), even if the value returned is not an image:

var img=new Image();
img.src='http://..full URL as above …';

When everything was done right is returned

<result code="done" />

otherwise would be:

<result code="something went wrong" />

Here's some PHP code to add a new bookmark to your account, in 2 simple ways:

function deliciousAdd($user, $pass, $url, $description, $extended, $tags) {
  $r=file("http://{$user}:{$pass}@del.icio.us/api/posts/add?url=".urlencode($url).
     "&description=".urlencode($description)."&extended=".urlencode($extended).
     "&tags=".urlencode($tags));
  return ($r[1]=="<result code=\"done\" />");
}

function deliciousAdd2($user, $pass, $url, $description, $extended, $tags)
   {
   $domain="del.icio.us";
   $socketConnection = fsockopen($domain, 80, $errno, $errstr);

   if (!$socketConnection) {
 echo("Network error: $errstr ($errno)");
   } else {
       $tmp = '';
       fputs($socketConnection,
 "GET /api/posts/add?url=".urlencode($url).
 "&description=".urlencode($description)."&extended=".urlencode($extended).
 "&tags=".urlencode($tags).
 " HTTP/1.0\r\nAuthorization: Basic ".base64_encode($user.":".$pass)."\r\n".
 "Host: $domain\r\nConnection: close\r\n\r\n");

       while (!feof($socketConnection)) {
           $tmp .= fgets($socketConnection, 128);
       }

       fclose ($socketConnection);

   }

return(strpos($tmp,"<result code=\"done\" />"));
}

They return TRUE or FALSE, depends on the response and could be use like:

deliciousAdd($username,$password,
    "http://Yahoo.com","Yahoo!","Yahoo","yahoo");

deliciousAdd2($username,$password,
    "http://Yahoo.com","Yahoo!","Yahoo","yahoo"); 

Simple, isn't it?

Comments

MSN Search API

Like other search engines, MSN made public a few APIs, including the most important: web search. They are using SOAP and could be used online from any other programming language and platforms.

As usual, first step is registration. You have to register your free application ID, needed in your web requests. MSN provided some MSDN help files and samples, but only for C# & VB.NET.

Our example here will be in PHP with NuSOAP. See it at work in this small demo (popup window). The PHP source code is this (only for MSN interrogation part):

# Use the NuSOAP php library
require_once('nusoap.php');

# Set parameters
$parameters = array(
  'AppID'=>'…your AppID…',
  'Query' => $_POST['key'],
  'CultureInfo' => 'en-US',
  'SafeSearch' => 'Off',
  'Requests' => array (
     'SourceRequest' => array (
         'Source' => 'Web',
         'Offset' => 0,
         'Count' => 10,
         'ResultFields'  => 'All' )
      )
   );

$soapclient =
    new soapclient('http://soap.search.msn.com/webservices.asmx');

$results = $soapclient->call('Search',array("Request"=>$parameters));

if( is_array($results['Responses']) ) {
  echo "<p><b>Your MSN query for '" . $_POST['key'] . "' found "
 . $results['Responses']['SourceResponse']['Total'] . ":</b></p>";
  foreach ( $results['Responses']['SourceResponse']['Results'] as $result ) {
 echo "<p><a href='" . $result['Url'] .
  "' target='_blank'>".$result['Title'].
  "</a><br />".$result['Description'].
  "<br />". $result['DisplayUrl']."</p>";
  }
 }
}

Don't forget to replace your AppID.

As you can see, the URL for web service is http://soap.search.msn.com/webservices.asmx and function name is 'Search'. You have to build proper parameters before calling function, most important 'Query', 'Source' (for web or local search), 'Offset' and 'Count' (how many results).

Results are returned as associative arrays, containing other arrays, for instance $results['Responses']['SourceResponse']['Results']['Url']. Hint: to see all fields, replace displaying part with a simple

print_r($results).

Usage limit is quite large: up to 10,000 queries a day. For more options see MSDN documentation.

Comments

· « Previous entries