11 January 2024

How to create events on google calender by any invitation email in PHP?

 <?php



require __DIR__ . '/vendor/autoload.php';


$client = new Google_Client();

$client->setAuthConfig('client_secret_397900761893-afl4gdg99gcfbaab0aip6jo1ha2824vg.apps.googleusercontent.com.json');

$client->setAccessType('offline');

$client->setPrompt('select_account consent');

$client->setRedirectUri('http://localhost'); // Update this line

$client->addScope(Google_Service_Calendar::CALENDAR);


$client->setHttpClient(new \GuzzleHttp\Client(['verify' => __DIR__ . '/cacert.pem']));


// If the token is not stored or expired, authenticate and generate a new one

if (!file_exists('token.json')) {

    // Redirect the user to the authorization URL

    $authUrl = $client->createAuthUrl();

    header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));

    exit;

} else {

    file_put_contents('debug_token.txt', file_get_contents('token.json'));

    $accessToken = json_decode(file_get_contents('token.json'), true);

}


// Set the access token to the client

$client->setAccessToken($accessToken);


// Create a Google Calendar service object

$service = new Google_Service_Calendar($client);


// Define the event details, including the guest's email in the attendees field

$event = new Google_Service_Calendar_Event(array(

    'summary' => '11 Client Meeting 11',

    'description' => 'Discuss project details with the client.',

    'start' => array(

        'dateTime' => '2024-01-13T10:00:00',

        'timeZone' => 'Asia/Kolkata',

    ),

    'end' => array(

        'dateTime' => '2024-01-13T11:00:00',

        'timeZone' => 'Asia/Kolkata',

    ),

));


// Add guests to the event

$event->setAttendees([

    ['email' => 'jas@gmail.com']

    ['email' => 'jas@yopmail.com'],

]);


// Insert the event into the primary calendar

$calendarId = 'primary';

$event = $service->events->insert($calendarId, $event, ['sendUpdates' => 'all']);


// Print the event ID

printf('Event created: %s', $event->getId());


No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...