I'm by no means a pro at php, but I do know it well enough to write my own basic scripts
XML is a different story, the way I learned php is by googling for examples, but I am having a problem understanding the basics of it.
I'm trying to create a lookup page using php, have created the form & all works well. The data is being passed in the link. & I know I need to create a page for the results (ie. whitepages_results.php)
Using this code (example) I found on http://code.google.com/p/php-whitepages/
--------------------------------------------------------------------------------------------------------------------------------------------------
<?php
require 'Net/WhitePages.php';
foreach ( $results->listings as $listing ) {
echo $listing->persons[0]['firstname'] . ' ';
echo $listing->persons[0]['lastname'];
if ( count($listing->phones) > 0 ) {
echo ' — ' . $listing->phones[0]['fullphone'];
}
echo '<br />';
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------
My questions are ...
1. (line 2) shouldn't that be a full link, such as http://api.whitepages.com/find_person
2. (line 4)
$lookup = new Net_WhitePages(API_KEY_HERE);
I use dreamweaver, which has color codes as a aid,
inserting my API Key between the ( ) can't be correct, shouldn't it be something like :
$lookup = new Net_WhitePages'12345688' ;
both ways brings back a error so I guess that can't be correct either..LOL!
Also, what if I choose to not use php, what do I do with the XML data, how could I simply have the results listed in say HTML on my site (mysite.com/whitepage_results.html)
Some basic examples would be great, but I'd much rather be able to understand it rather that just throw someone else work on my site, I'd be most grateful for any help anyone can give me, in the mean time, it's back to google for me!
I've managed to get the data on my page, but how do I go about only listing each field as a single line?
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://api.whitepages.com/find_person/1.0?firstname=John&lastname=Smith&house=&street=&city=&state=VA&zip=&areacode=&outputtype=XML&api_key=791d85091e5314e42ee810ee6f1bf225");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
Just a update, I've been searching for answers on the web but still no luck, I do see there are several different ways to display the results of the people search (or any XML file) including curl, css & javascript. By now I know this entire forum & docs by heart, all the sample code comes back with errors so no luck there either. Hopefully someone will give me a hand & point me in the right direction, I see this is a new feature (whitepages API), I even found a nice you-tube video on the developers of this as well as basic information http://www.youtube.com/watch?v=0Et2GcmiMcs I think it's great that Whitepages went to the trouble & cost to develop this as it has already taught me a lot (just not enough quite yet though!!)
require 'Net/WhitePages.php';
define (API_KEY_HERE,'000ddd000ddd000ddd000dd0dd0000dd0'); // not a real key of course
$lookup = new Net_WhitePages(API_KEY_HERE);
See if this fixes the error with the API_KEY_HERE, the key is a string and so needs to be in quotes.
Net_WhitePages does all the XML parsing and converts to a simple php data structure. You could look inside the module as to how that's done if you really want to get into it, it does it old school using the DOM_XML.
Wow, thanks for the reply, this has opened my eyes a little, still haveing a little trouble though...
1. Can't seem to get past this error
parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/username/public_html/Net/WhitePages.php on line 26
2. Net/WhitePages.php file
Line 34
private $_api_key;
I'm guessing should be
private $_api_key; = '8894893983298'; //fake key
OK, I take back that the problem was HostGaator, it was but Hostgator is currently updating to php 5, for now they just gave me some code that I put in the http access file, did the trick!!!
I did get it to run, sort of!!
I got a error in the google php code,
Invalid argument supplied for foreach() in /home/username/public_html/test.php on line 20
but when I simple delete that line of code
foreach ( $search->listings as $listing )
I get the result :
— No Phone Listed
I've tried several different names, other than James Bond, with the same result
I'm getting SOOOO close! I guess that not having php 5 was the biggest problem in the first place!
SOLUTION FOUND! I knew I had everything right, nothing I did worked, I went over everything over & over, it turns out I was right the entire time (but I learned a lot in the process)
First, the problem was PHP5 had to be installed. That never really crossed my mind, I'm thinking Hostgator always had the latest versions of everything!. They do on their shared hosting packages, but not on the Resellers packages...yet.
Their temp. fix was to .... quote..
Simply insert this code into your htaccess file:
AddHandler application/x-httpd-php5 .php
I did that & the NET/whitepages file ran, but it wasn't passing any data at all. The rest of the site, same thing...would not pass any PHP data.....
removed it, data was again being passed
So I guess I'll get one of their shared accounts for now, my mind is set on finding out if the code was right all the time.
So if anyone else has problems, check & make sure PHP5 is installed.
I've just registered and received my api_key. When I try to access using my own cell phone number and my new api key in a browser it works and returns the XMP as expected. However, at the LINUX command prompt using curl (and wget for that matter), I still get the "403: Forbidden" message...and I've waited at least 30 minutes now.
I am not fluent in PHP, but I do understand it. I have edited code and added my own through trial-and-error after installing/using several CMS packages over the years.
But I cannot get this to work. I managed to stop the errors, particularly with the FOREACH statement by adding (array) at the beginning so it looks like: foreach ( (array) $search->listings as $listing ) * this got rid of the invalid argument supplied... error.
No errors now, but no listings either. I have tried the code from BaldPenguin, above, and the one from Google's page which is were I got WhitePages.php. I also added the suggested line to my htaccess file.
Hopefully just a simple error, the listings attribute appears to be null, forcing the invalid args. Casting to array seems to force the null to an empty array. Do you have a sample of the query you are running? Have you tried running the query on WhitePages.com? Just interested to see if data is returned there.
My php version is 5.3.5.I have used Net/WhitePages.php.But this php file shows an error like "Call to a member function getAttribute() on a non-object" in :
I'm by no means a pro at php, but I do know it well enough to write my own basic scripts
XML is a different story, the way I learned php is by googling for examples, but I am having a problem understanding the basics of it.
I'm trying to create a lookup page using php, have created the form & all works well. The data is being passed in the link. & I know I need to create a page for the results (ie. whitepages_results.php)
Using this code (example) I found on http://code.google.com/p/php-whitepages/
--------------------------------------------------------------------------------------------------------------------------------------------------
<?php
require 'Net/WhitePages.php';
$lookup = new Net_WhitePages(API_KEY_HERE);
$results = $lookup->find_person(
array(
'firstname' => 'J*',
'lastname' => 'Bond',
'state' => 'WA',
'city' => 'Seattle'
)
)
foreach ( $results->listings as $listing ) {
echo $listing->persons[0]['firstname'] . ' ';
echo $listing->persons[0]['lastname'];
if ( count($listing->phones) > 0 ) {
echo ' — ' . $listing->phones[0]['fullphone'];
}
echo '<br />';
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------
My questions are ...
1. (line 2) shouldn't that be a full link, such as http://api.whitepages.com/find_person
2. (line 4)
$lookup = new Net_WhitePages(API_KEY_HERE);
I use dreamweaver, which has color codes as a aid,
inserting my API Key between the ( ) can't be correct, shouldn't it be something like :
$lookup = new Net_WhitePages'12345688' ;
both ways brings back a error so I guess that can't be correct either..LOL!
Also, what if I choose to not use php, what do I do with the XML data, how could I simply have the results listed in say HTML on my site (mysite.com/whitepage_results.html)
Some basic examples would be great, but I'd much rather be able to understand it rather that just throw someone else work on my site, I'd be most grateful for any help anyone can give me, in the mean time, it's back to google for me!
Message edited by tommy 7 months ago
tommy – 5 years ago
I've managed to get the data on my page, but how do I go about only listing each field as a single line?
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://api.whitepages.com/find_person/1.0?firstname=John&lastname=Smith&house=&street=&city=&state=VA&zip=&areacode=&outputtype=XML&api_key=791d85091e5314e42ee810ee6f1bf225");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
tommy – 5 years ago
Just a update, I've been searching for answers on the web but still no luck, I do see there are several different ways to display the results of the people search (or any XML file) including curl, css & javascript. By now I know this entire forum & docs by heart, all the sample code comes back with errors so no luck there either. Hopefully someone will give me a hand & point me in the right direction, I see this is a new feature (whitepages API), I even found a nice you-tube video on the developers of this as well as basic information http://www.youtube.com/watch?v=0Et2GcmiMcs I think it's great that Whitepages went to the trouble & cost to develop this as it has already taught me a lot (just not enough quite yet though!!)
BaldPenguin – 5 years ago
require 'Net/WhitePages.php';
define (API_KEY_HERE,'000ddd000ddd000ddd000dd0dd0000dd0'); // not a real key of course
$lookup = new Net_WhitePages(API_KEY_HERE);
header('Content-type: text/html');
$search = $lookup->find_person(
array(
'firstname' => 'James',
'lastname' => 'Bond',
'state' => 'VA'
)
);
?><html>
<head>
<title>Example</title>
</head>
<body>
<?
foreach ( $search->listings as $listing ) {
echo $listing->persons[0]['firstname'];
echo ' ';
echo $listing->persons[0]['lastname'];
echo ' — ';
if ( count($listing->phones) > 0 ) {
echo $listing->phones[0]['fullphone'];
}
else {
echo 'No Phone Listed';
}
echo '<br />';
}
?>
</body>
</html>
See if this fixes the error with the API_KEY_HERE, the key is a string and so needs to be in quotes.
Net_WhitePages does all the XML parsing and converts to a simple php data structure. You could look inside the module as to how that's done if you really want to get into it, it does it old school using the DOM_XML.
tommy – 5 years ago
Wow, thanks for the reply, this has opened my eyes a little, still haveing a little trouble though...
1. Can't seem to get past this error
parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/username/public_html/Net/WhitePages.php on line 26
2. Net/WhitePages.php file
Line 34
private $_api_key;
I'm guessing should be
private $_api_key; = '8894893983298'; //fake key
3. Net/WhitePages.php file
Line 38
private $_useragent;
I also need to complete that correct?
tommy – 5 years ago
sorry, I think I found the problem, HOSTGATOR!
This error is encountered when Moodle is running on PHP 4.x and on a shared hosting. Update to PHP ver 5.x and try again.
tommy – 5 years ago
OK, I take back that the problem was HostGaator, it was but Hostgator is currently updating to php 5, for now they just gave me some code that I put in the http access file, did the trick!!!
I did get it to run, sort of!!
I got a error in the google php code,
Invalid argument supplied for foreach() in /home/username/public_html/test.php on line 20
but when I simple delete that line of code
foreach ( $search->listings as $listing )
I get the result :
— No Phone Listed
I've tried several different names, other than James Bond, with the same result
I'm getting SOOOO close! I guess that not having php 5 was the biggest problem in the first place!
tommy – 5 years ago
SOLUTION FOUND! I knew I had everything right, nothing I did worked, I went over everything over & over, it turns out I was right the entire time (but I learned a lot in the process)
First, the problem was PHP5 had to be installed. That never really crossed my mind, I'm thinking Hostgator always had the latest versions of everything!. They do on their shared hosting packages, but not on the Resellers packages...yet.
Their temp. fix was to .... quote..
Simply insert this code into your htaccess file:
AddHandler application/x-httpd-php5 .php
I did that & the NET/whitepages file ran, but it wasn't passing any data at all. The rest of the site, same thing...would not pass any PHP data.....
removed it, data was again being passed
So I guess I'll get one of their shared accounts for now, my mind is set on finding out if the code was right all the time.
So if anyone else has problems, check & make sure PHP5 is installed.
Saren – 5 years ago
what is the difference in REST
SOAP
XML
JSON
crosbdc – 5 years ago
I've just registered and received my api_key. When I try to access using my own cell phone number and my new api key in a browser it works and returns the XMP as expected. However, at the LINUX command prompt using curl (and wget for that matter), I still get the "403: Forbidden" message...and I've waited at least 30 minutes now.
Any ideas?
Dan_WhitePages – 5 years ago
Saren,
I suggest you read
http://www.ajaxonomy.com/2008/xml/web-services-part-1-soap-vs-rest
XML is an output format, JSON is a different type.
You can learn more about XML
http://www.w3schools.com/XML/xml_whatis.asp
and JSON
http://json.org/
Dan_WhitePages – 5 years ago
crosbdc
Are you enclosing the url in single quotes? I access the API all the time using cURL.
You have to make sure the shell isn't interpreting the ?
This is what works for me.
curl 'http://api.whitepages.com/find_business/1.0/?;category=doctor;zip=98104;api_key=API_KEY'
MikeWCFL – 5 years ago
I am not fluent in PHP, but I do understand it. I have edited code and added my own through trial-and-error after installing/using several CMS packages over the years.
But I cannot get this to work. I managed to stop the errors, particularly with the FOREACH statement by adding (array) at the beginning so it looks like: foreach ( (array) $search->listings as $listing ) * this got rid of the invalid argument supplied... error.
No errors now, but no listings either. I have tried the code from BaldPenguin, above, and the one from Google's page which is were I got WhitePages.php. I also added the suggested line to my htaccess file.
My server has PHP v5.2.6
Any working ideas? Thanks for the help!
Mike
BaldPenguin – 5 years ago
Hopefully just a simple error, the listings attribute appears to be null, forcing the invalid args. Casting to array seems to force the null to an empty array. Do you have a sample of the query you are running? Have you tried running the query on WhitePages.com? Just interested to see if data is returned there.
Saddam Hossain – 7 months ago
My php version is 5.3.5.I have used Net/WhitePages.php.But this php file shows an error like "Call to a member function getAttribute() on a non-object" in :
$this->result_type = $resultNode->getAttribute('type'); $this->result_code = $resultNode->getAttribute('code');
how i solve the problem?