$theguardian->parameters->url = 'http://www.facebook.com/theguardian'; $theguardian->parameters->title = 'Some news page'; $theguardian->parameters->id = 'theguardian'; //or using an array $ladyGaga = new stdClass(); $ladyGaga->parameters = array('url' => 'http://www.facebook.com/ladygaga', 'title' => 'Lady Gaga', 'id' => 'ladygaga'); $resources = array($theguardian, $ladyGaga); $facebookAuth1 = new stdClass(); $facebookAuth1->parameters = new stdClass(); $facebookAuth1->parameters->value = 'facebook_token'; //one or more facebook OAuth tokens can be used to manage the resources $auth = array($facebookAuth1); $source = new DataSift_Source($user, array('name' => 'My PHP managed source', 'source_type' => 'facebook_page', 'parameters' => $params, 'auth' => $auth, 'resources' => $resources)); //create the managed source - note the same method is used to update an existing //managed source if an ID is set on the object try { $source->save(); } catch (Exception $e) { print_r($e->getMessage()); } //after saving the source will have an ID, created at time etc... echo 'Created managed source ==> ' . $source->getId(); //Add an extra resource $nintendo = new stdClass(); $nintendo->parameters = array('url' => 'http://www.facebook.com/nintendo', 'title' => 'Nintendo', 'id' => 'nintendo'); $source->addResource(array($nintendo)); $resources = $source->getResources(); //remove the first resource $source->removeResource(array($resources[0]['resource_id'])); //Check for log messages $logs = $source->getLogs();
// Include the configuration - put your username and API key in this file require dirname(_FILE_) . '/../config.php'; // Autheticate echo "Creating user...\n"; $user = new DataSift_User('USER', 'API'); // Setting up the specific resources of the Managed Source $ODPex = new stdClass(); $ODPex->parameters = new stdClass(); $ODPex->parameters->category = '6d2420bffa3d4fda9a85ccb47f626890_1'; $ODPex->parameters->idml = "web.link = id\r\nweb.content = body"; $resources = array($ODPex); // Create new ODP Managed Source $source = new DataSift_Source($user, array('name' => 'My ODP Managed Source', 'source_type' => 'custom', 'resources' => $resources)); try { $source->save(); } catch (Exception $e) { print_r($e->getMessage()); } // Assign the Source ID to a vaiable $source_id = $source->getId(); // Setting up a data set array to send to the endpoint $data = array(array('id' => '234', 'body' => 'yo'), array('id' => '898', 'body' => 'hey')); $data_set = ""; foreach ($data as $entry) { $data_set .= json_encode($entry) . "\n"; } // Create the ODP object $odp = new DataSift_ODP($user, $source_id); // Use the ingest function and make an API request $response = $odp->ingest($data_set); var_dump($response);