public function testTailoredAudienceChangesCanBeFetchedAndUpdated()
 {
     $this->markTestSkipped('waiting for write access to twitter ads api');
     $accounts = $this->twitter->getAccounts();
     $this->assertGreaterThan(0, count($accounts));
     $account = iterator_to_array($accounts)[0];
     $audience = new TailoredAudience($account);
     $audience->setListType(TailoredAudience::LIST_TYPE_EMAIL);
     $audience->save();
 }
 /**
  * Asserts that the given type is valid
  *
  * @param string $type
  * @throws InvalidType - if type is invalid or null
  *
  * @return string
  */
 private function assureValidType($type)
 {
     foreach (TailoredAudience::getTypes() as $allowedType) {
         if ($type === $allowedType) {
             return $type;
         }
     }
     throw new InvalidType(sprintf('"%s" is not a valid type for %s', $type, TailoredAudience::class));
 }
 public function testTailoredAudiencesCanBeFetched()
 {
     $audience = new TailoredAudience($this->account);
     $result = iterator_to_array($audience->all());
     $this->assertGreaterThan(0, $result);
 }
use Hborras\TwitterAdsSDK\TwitterAds;
use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudience;
require '../autoload.php';
const CONSUMER_KEY = 'your consumer key';
const CONSUMER_SECRET = 'your consumer secret';
const ACCESS_TOKEN = 'your access token';
const ACCESS_TOKEN_SECRET = 'your access token secret';
const ACCOUNT_ID = 'account id';
/** Create twitter ads client */
$twitterAds = new TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
/** If the file is too large, I highly recommend increase the timeout */
$twitterAds->setTimeouts(5, 45);
// Retrieve account information
$account = $twitterAds->getAccounts(ACCOUNT_ID);
/** If the file is not hashed line by line, you need to hash it, for example for emails is this code*/
$file = fopen("path/to/list.txt", "r");
$newFile = fopen('path/to/new_list.txt', 'w');
while (!feof($file)) {
    $line = fgets($file);
    $normalized_email = strtolower(trim($line, " \t\r\n\v."));
    $normalized_email = hash('sha256', $normalized_email);
    fwrite($newFile, $normalized_email . "\n");
    # do same stuff with the $line
}
fclose($newFile);
fclose($file);
$audience = new TailoredAudience($account);
$audience->create('path/to/new_list.txt', 'Test List', TailoredAudience::LIST_TYPE_EMAIL);
/** @var TwitterAds\TailoredAudience\TailoredAudienceChanges $status */
$status = $audience->status();
print_r($status->getState());
 /**
  * @expectedException Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\Exception\InvalidType
  */
 public function testTailoredAudiencesWillThrowAnExceptionWithAnInvalidType()
 {
     $audience = new TailoredAudience(null);
     $audience->setListType('nope');
 }