Skip to content
Vladimir Jimenez edited this page Sep 19, 2015 · 2 revisions

There are two main objects that are required in order to interact with the Socrata API: the client and the dataset object.

SodaClient

The SodaClient is used to handle and store the information needed to call the Socrata API such as the domain, tokens, and credentials.

$sc = new SodaClient($url, $token = "", $email = "", $password = "")
  • $url
    The minimum a SodaClient requires is the domain of the API endpoint; just the domain

  • $token
    In order to reduce throttling, applications should have tokens

  • $email
    Some actions, such as writing datasets or accessing private datasets, require authentication

  • $password
    ...and the password for the authentication

OAuth2.0

Fetching the OAuth2.0 token is not handled by the PhpSoda library but passing the token to Socrata in API calls is supported with SodaClient::setOAuth2Token().

$sc->setOAuth2Token("<token>");

SodaDataset

The SodaData is used to interact with a dataset and it requires a SodaClient instance in order to make the API calls.

$ds = new SodaDataset($sodaClient, $resourceID);
  • $sodaClient
    A SodaClient object which contains all of the information about the API endpoint and the credentials to use, if any, to access that dataset

  • $resourceID
    The 4x4 unique identifier for your dataset; it's the thing that looks like pkfj-5jsd

Example Usage

Here's an example of how to retrieve a dataset.

$sc = new SodaClient("opendata.socrata.com");
$ds = new SodaDataset($sc, "pkfj-5jsd");

$results = $ds->getDataset();