Click here to Skip to main content
Licence CPOL
First Posted 16 Mar 2010
Views 4,751
Downloads 38
Bookmarked 5 times

Parse White Pages API using JQuery

By | 16 Mar 2010 | Article
Basic example of the White Pages People and Reverse Phone Searches

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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalsearch Pinmembermohit110:38 22 Oct '10  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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