0

I use the following code to retrieve the vacation settings. It uses the Google API PHP client library and the Gmail API to gain access to the gmail platform

I cannot work out how to set a vacation. Does anyone have some sample code that does this?

    public function getVacation($userToken)
    {
        // Get the API client and construct the service object.
        $client = $this->getClient($userToken);
        $service = new Google_Service_Gmail($client);

        // get the vacation settings
        $user = 'me';
        $results = $service->users_settings->getVacation($user);
        print_r($results);
    }


function getClient($userToken)
{
   ... a method that does the connection. for some reason stackoverflow sees it as too much code, but it works :) and i get vacation info.
}
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • this is the code i am using. – Kevin Revill Oct 22 '18 at 09:57
  • `public function setVacation($userToken) { // Get the API client and construct the service object. $client = $this->getClient($userToken); $service = new Google_Service_Gmail($client); // get the vacation settings $user = 'me'; $results = $service->users_settings->getVacation($user); print_r($results); // change the subject $results->responseSubject = 'Out of Office.'; $results2 = $service->users_settings->updateVacation($user,$vacation); print_r($results2); }` – Kevin Revill Oct 22 '18 at 09:57
  • getting error Argument 2 passed to Google_Service_Gmail_Resource_UsersSettings::updateVacation() must be an instance of Google_Service_Gmail_VacationSettings, null given – Kevin Revill Oct 22 '18 at 10:00

1 Answers1

0

You should look into using Update vacation

$results = $service->users_settings->getVacation("me");
$results->responseSubject = 'Out of Office.';
$results = $service->users_settings->updateVacation("me", $results);
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449