AvatarAPI.com – Get a name and profile pic from a #Gmail address
Do you find that your users never upload decent profile images?, and you end up with pages with lots of default silhouette icons in place of profile pics?, or perhaps you have a database with plenty of email addresses, but no name to put to them – so you end up sending out emails with “Dear Sir or Madam” instead of “Dear Mr James Smith” , this service at AvatarAPI.com allows you to use a simple API to solve those problems.
It’s easy to implement in either PHP, C#, or any other language that can make a HTTP request and parse XML.
HTTP useage
You can call this via any client capable of making a HTTP request, in it’s simplist form, you make a GET request as follows
(where xxxx is your username and password)
And you will receive XML as follows
<profile xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://avatarapi.com/”>
<Name>Peter Smith</Name> <Image> </Image> <Valid>true</Valid> </profile> |
PHP implementation
You can call the webservice via PHP using code such as the following:
Replacing the xxxxx with your username and password.
<?php
$client = new SoapClient(“http://www.avatarapi.com/avatar.asmx?wsdl”); $params = array ( “email” => “john.reid@gmail.com”, “username” => “xxxxx”, “password” => “xxxxxx” ); $response = $client->__soapCall(‘GetProfile’, array($params)); print_r($response); ?> |
C# implementation
To use C# to call this API, you must first add a web service reference to your project by right clicking Add > Service Reference, and entering the url http://www.avatarapi.com/avatar.asmx
You can call the namespace “Avatar”, for the purposes of this example, then just add this code into a console app;
Replacing the xxxxx with your username and password.
var avatar = new avatarSoapClient();
var profile = avatar.GetProfile(“john.reid@gmail.com”, “xxxx”, “xxxx”); Console.WriteLine(profile.Name); Console.ReadLine(); |