public function testCrud() { $account = new AdAccount($this->getConfig()->accountId); $job = $account->getInsightsAsync(); $this->assertTrue($job instanceof AsyncJobInsights); $this->waitTillJobComplete($job); $job->getResult(); }
public function testFields() { $account = new AdAccount($this->getConfig()->accountId); $fields = array(AdAccountFields::NAME); $account->read($fields); $fields = array(InsightsFields::ACCOUNT_NAME); $job = $account->getInsightsAsync($fields); $this->assertTrue($job instanceof AsyncJobInsights); $this->waitTillJobComplete($job); $result = $job->getResult(); $this->assertEquals($result[0]->{InsightsFields::ACCOUNT_NAME}, $account->{AdAccountFields::NAME}); }
function queryTotal(array $dimensions, $column, \DateTime $date) { $account = new AdAccount(requireEnv('FACEBOOK_ACCOUNT_ID')); $collapsedDimensions = implode(',', $dimensions); $params = ['breakdowns' => $collapsedDimensions, 'level' => InsightsLevels::ADSET, 'time_range' => ['since' => $date->format('Y-m-d'), 'until' => $date->format('Y-m-d')]]; $asyncJob = $account->getInsightsAsync([], $params); echo sprintf("Created async job %s (%s)\n", $asyncJob->getData()['id'], $collapsedDimensions); $result = waitForJobToComplete($asyncJob); $total = 0; foreach ($result as $row) { $data = $row->getData(); $total += $data['spend']; } return $total; }