Factual Blog /

Factual PHP Driver

We are pleased to report the availability of the official PHP driver for the Factual API. This driver wraps our Read, Crosswalk, Resolve, and Schema APIs, providing five-line access to our 55 million global places and other structured data.


Getting Started:

First, get an API key from Factual. Add your oauth key and secret to the constructor:

	$factual = new Factual("yourOauthKey","yourOauthSecret");

Follow with syntax specific to the selected API:

Read [docs]

The driver provides the same powerful abilities to query, filter, order, and sort as provided via the REST API:

	//Free text query
	$query = new FactualQuery;
	$query->search("Sushi Santa Monica");  //searches across numerous fields
	$query->field("country")->equal("US"); //limit results to the US
	$res = $factual->fetch("places", $query);

	//Search near a point
	$query = new FactualQuery;
	$query->within(new FactualCircle(34.06018, -118.41835, 5000)); //5k meter radius
	$query->limit(10); //only get ten results
	$query->sortAsc("\$distance"); //order results by distance
	$res = $factual->fetch("places", $query);

We also allow for nested conditions and the complete range of parametric operators. If we have it, you can find it.

Resolve [docs]

Provided to meet all of your entity enrichment and matching needs:

	//Find a match at a specific lon/lat
	$query = new ResolveQuery();
	$query->add("name", "Buena Vista Cigar Club");
	$query->add("latitude", 34.06);
	$query->add("longitude", -118.40);
	$res = $factual->fetch("places", $query);

Crosswalk [docs]

Find third-party identifiers and URLs:

	//Get all crosswalks for a specific Factual ID
	$query = new CrosswalkQuery();
	$res = $factual->fetch("places", $query);

Schema [docs]

Table introspection:

	//Get the schema for the Global Places table
	$res = $factual->schema("places");


And we’ve thrown in some cheeky geocoding:

	//geocode (convert an address to a longitude and latitude)
	$res = $factual->geocode("425 Sherman Ave, Palo Alto, CA, USA");

	//reverse geocode (convert an address to a longitude and latitude)
	$res = $factual->reverseGeocode(-122.143895,37.425674);

Factual does not provide a geocoding service, so these use a third-party; we’ve included these methods as convenient, if simple, hooks. Like the MPAA’s claims that online piracy is ruining America’s economy, they are unsupported.

Get It Here

The driver is open source and can be downloaded from https://github.com/Factual/factual-php-driver.  Example code and detailed commentary are provided in the PHP Driver Readme. Driver support and feature requests can be pinged to the Factual Developer Group. Rockin.

-Tyler Bell
Director of Product