public function testGetSource() { $response = array('response_code' => 200, 'data' => array('id' => '78b3601ef667466d95f19570dcb74699', 'name' => 'My PHP managed source', 'created_at' => 1435869526, 'status' => 'active', 'auth' => array(array('identity_id' => '7b1be3a398e646bbb3c7a5cb9717ba45', 'expires_at' => 1495869526, 'parameters' => array('value' => '363056350669209|09af1ce9c5d8d23147ec4eeb9a33aac2'))), 'resources' => array(array('resource_id' => '30bc448896de44b88604ac223cb7f26f', 'status' => 'valid', 'parameters' => array('url' => 'http://www.facebook.com/theguardian', 'title' => 'The Guardian', 'id' => 10513336322))), 'parameters' => array('comments' => true, 'likes' => true, 'page_likes' => true, 'posts_by_others' => true)), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $source = DataSift_Source::get($this->user, '78b3601ef667466d95f19570dcb74699'); $resources = $source->getResources(); $auth = $source->getAuth(); $this->assertEquals($source->getId(), '78b3601ef667466d95f19570dcb74699', 'Source ID did not match'); $this->assertEquals($source->getName(), 'My PHP managed source', 'Name did not match'); $this->assertEquals($resources[0]['parameters']['id'], 10513336322, 'Resource ID did not match'); $this->assertEquals($auth[0]['parameters']['value'], '363056350669209|09af1ce9c5d8d23147ec4eeb9a33aac2', 'Auth token did not match'); }
//can create using an stdClass if preferred $theguardian = new stdClass(); $theguardian->parameters = new stdClass(); $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
*/ // Include the DataSift library require dirname(_FILE_) . '/../lib/datasift.php'; // 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);