Google-api-php-client: Uncaught Google_Service_Exception:

Created on 25 Mar 2020  路  5Comments  路  Source: googleapis/google-api-php-client

I try to user $_POST variable on dateTime .

this my code

require('configDB.php');
date_default_timezone_set("Asia/Bangkok");
$conn=$DBconnect;
require __DIR__ . '/vendor/autoload.php';
$date = $_POST['date'];
$eventname =$_POST['event'];
$start=$_POST['start'];
$end =$_POST['end'];
$enddate = $_POST['enddate'];
$time_period=$_POST['time_period'];
$room_id=$_POST['room_id'];


$dateyimestart=date_create($date.$start);

$dateselectst = date_format($dateyimestart,"Y-m-dTH:i:s+07:00");

$event = new Google_Service_Calendar_Event(array(
    'summary' => $eventname,
    'location' => '喔腑喔涏福喔班笂喔膏浮喔涪喔膏笜喔⑧覆',
    'description' => '喔佮覆喔`笡喔`赴喔娻父喔∴笚喔斷弗喔竾.',  
    'start' => array(
      'dateTime' => $dateselectst,
      'timeZone' => 'Asia/Bangkok',
    ),
    'end' => array(
      'dateTime' => '2020-03-25T16:30:00+07:00',
      'timeZone' => 'Asia/Bangkok',
    ),
    'recurrence' => array(
      'RRULE:FREQ=DAILY;COUNT=1'
    ),
    'attendees' => array(
      array('email' => '[email protected]'),
      array('email' => '[email protected]'),
      // array('email' => '[email protected]'),
    ),
    'reminders' => array(
      'useDefault' => FALSE,
      'overrides' => array(
        array('method' => 'email', 'minutes' => 24 * 60),
        array('method' => 'popup', 'minutes' => 10),
      ),
    ),
  ));
  print_r($event);
  $calendarId = 'primary';
  $event = $service->events->insert($calendarId, $event);
  // printf('Event created: %s\n', $event->htmlLink);



if (empty($events)) {
    print "No upcoming events found.\n";
} else {
    print "Upcoming events:<br/>\n";
    foreach ($events as $event) {
        $start = $event->start->dateTime;
        if (empty($start)) {
            $start = $event->start->date;
        }
        printf("%s (%s)<br/>\n", $event->getSummary(), $start);
    }
}
question

All 5 comments

What is the error?

Error is when I use $dateselectst in 'start' => array can't send variable to google calendar.
this is error
PHP Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
],
"code": 400,
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
}

Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
],
"code": 400,
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
}

Something is invalid here:

$dateyimestart = date_create($date.$start);
$dateselectst = date_format($dateyimestart,"Y-m-dTH:i:s+07:00");

Make sure $dateselectst is not false. If your input or format is invalid, it will.

I'm going to close this issue out. If you're still having trouble, please feel free to re-open!

thank you so much ,i can fix my code now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cmcfadden picture cmcfadden  路  5Comments

whatido1 picture whatido1  路  3Comments

kungufli picture kungufli  路  3Comments

ysaurabh33 picture ysaurabh33  路  3Comments

slaFFik picture slaFFik  路  5Comments