<?php
error_reporting(E_ALL); 
ini_set('display_errors', 1);

// Incluimos la configuración Zoom (que ya carga .env)
include 'zoom_config.php';

function getZoomToken() {
    $url = 'https://zoom.us/oauth/token?grant_type=account_credentials&account_id=' . ZOOM_ACCOUNT_ID;

    $headers = [
        'Authorization: Basic ' . base64_encode(ZOOM_CLIENT_ID . ':' . ZOOM_CLIENT_SECRET),
        'Content-Type: application/x-www-form-urlencoded'
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true); // método POST
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // temporal para pruebas

    $response = curl_exec($ch);

    if (curl_errno($ch)) {
        echo 'Error en solicitud cURL: ' . curl_error($ch);
        curl_close($ch);
        return null;
    }

    curl_close($ch);

    $tokenInfo = json_decode($response, true);

    if (isset($tokenInfo['access_token'])) {
        return $tokenInfo['access_token'];
    } else {
        echo 'Error de Zoom: ' . $response;
        return null;
    }
}

$token = getZoomToken();

if ($token) {
    echo 'Token obtenido correctamente: ' . $token;
}

