Click here to Skip to main content
Click here to Skip to main content

Parse White Pages API using JQuery

By , 16 Mar 2010
 

Introduction

Searched for some examples on the White Pages Json API, and haven't found much. If you look at their documentation, http://developer.whitepages.com/docs, you'll notice a pretty good explanation of everything, but it does take a little time to parse everything out. I turned to the YQL Console in order to test and figure out how everything was broken down and developed a script to have a basic search of People by Name and Zip Code, and a Reverse Phone Number Search in order to tell what number belongs to who.

For further information, I am using YQL, (documentation is found at: http://developer.yahoo.com/yql/), and the White Pages API, (documentation is found at: http://developer.whitepages.com).

Using the Code

If you download the source, it will not work until you have signed up with Whitepages.com first in order to get an API Key. Once you have this, simply plug it into the 2 javascript files located under the Scripts/whitepages folder at the top where it says:

var apiKey = 'YOUR API KEY';

The scripts themselves are pretty lengthy, so I'll keep the summary fairly short...

function findPerson(name,zip) {   
$('#data').empty();
 var apiKey = 'YOUR API KEY';
var query = 'select * from json where url=" + name + 
	';zip=' + zip + ';api_key=' + apiKey + ';outputtype=JSON"'
  $.getJSON(
  "http://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(query) + 
	"&format=json&callback=?",
  function(data) {
      $.each(data.query.results,
    function(index, item) {
      if (item.result.code == 'Found Data') {
    // Declare variables and display data
if (item.meta.recordrange.totalavailable == 1) {
//One item was found, parse accordingly
}
}
else{
// Multiple items are found, parse accordingly
}
else{
//No items were found
}}  
function findNumber(number) {   
$('#phoneData').empty();
 var apiKey = 'YOUR API KEY';
var query = 'select * from json where url=" + number + ';api_key=' + 
	apiKey + ';outputtype=JSON"';  
$.getJSON(
  "http://query.yahooapis.com/v1/public/yql?q=" + 
	encodeURIComponent(query) + "&format=json&callback=?",
  function(data) {
      $.each(data.query.results,
    function(index, item) {
      if (item.result.code == 'Found Data') {
    // Declare variables and display data
}
else{
//No items were found
}}   

Pretty much it.
View sample for further details.

A live example is located at http://www.joshuablackstone.net/WhitePagesAPI. (Forgive the Godaddy ads... lol).

Finally, I realize that there may be better ways to do this, and I am NOT an expert in JavaScript, so if you have a way to make this even better, then feel free to comment.

History

  • 16th March, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Joshua Blackstone
Other SRI Incorporated
United States United States
Member
I am an Application Developer in Indianapolis, IN. I work primarily with ASP.NET (VB), and Microsoft Access.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalsearchmembermohit1122 Oct '10 - 0:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 Mar 2010
Article Copyright 2010 by Joshua Blackstone
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid