Error while trying to make a request with curl

33 views Asked by At

I am using ELECTRON-4-PHP and when I try to make a request with curl and then run it with npm I get the error:

Fatal error: Uncaught Error: Call to undefined function curl_init() in C:\Users\Admin\Documents\test\callback.php:29 Stack trace: #0 {main} thrown in C:\Users\Admin\Documents\test\callback.php on line 29.

I have checked if curl was enabled in php.ini and it was and I have reinstalled php and curl

if (isset($_GET['code'])) {
    // Step 1: Extract the authorization code from the URL parameters
    $code = $_GET['code'];

    // Step 2: Exchange the authorization code for an access token
    $tokenRequestData = array(
        'grant_type' => 'authorization_code',
        'client_id' => CLIENT_ID,
        'client_secret' => CLIENT_SECRET,
        'code' => $code,
        'redirect_uri' => REDIRECT_URI
    );

    $ch = curl_init(TOKEN_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($tokenRequestData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

    $responseData = json_decode($response, true);

    if (isset($responseData['access_token'])) {
        // Step 3: You have successfully obtained the access token
        $accessToken = $responseData['access_token'];

        // Now you can use $accessToken to make API calls to fetch the calendar events
    } else {
        handle_error('Unable to obtain access token');
    }
} else {
    handle_error('Authorization code not found');
}
0

There are 0 answers