2017-12-05 14 views
-1

次のコードを使用してイベントを作成しましたが、エラーが発生しました。GoogleカレンダーAPI PHP(400)終了時間がありません

$service = new Google_Service_Calendar(); 
$calendarId = "<some calendar id>"; 
$startDate = "2017-12-04"; 
$startTime = "18:00:00"; 
$endDate = "2017-12-04"; 
$endTime = "19:00:00"; 
$tzOffset = "+08"; 
$newEvent = new Google_Service_Calendar_Event(); 
$newEvent->setSummary("title"); 
$newEvent->setLocation("where"); 
$start = new Google_Service_Calendar_EventDateTime(); 
$start->setDateTime("{$startDate}T{$startTime}.000{$tzOffset}:00"); 
$newEvent->setStart($start); 
$end = new Google_Service_Calendar_EventDateTime(); 
$end->setDateTime("{$endDate}T{$endTime}.000{$tzOffset}:00"); 
$newEvent->setEnd($end); 
$newEvent->setDescription("desc"); 

$result = $service->events->insert($calendarId, $newEvent); 

結果は以下のとおりです。

Error calling PUT <some url>: (400) Missing end time. 

何が問題なのですか。助けてください。ありがとう!

答えて

0

私はついにその理由を理解しました。それは私の悪かったです。

この機能は、システムのスケジュールに基づいてGoogleカレンダー全体のスケジュールを作成することでした。私はこの関数の前に要約フィールドを切り詰めようとしました。問題は、要約フィールドがマルチバイト文字列であり、切り捨てにsubstr()を使用したときに結果の文字列に不要な文字が含まれる可能性があるためです。これらの文字は、APIによって作成されたJSONの形式を誤っていました。そして、おそらくサーバーはJSONを適切に解析して、属性、たとえば終了時刻属性を取得できませんでした。エラーメッセージは正しくありましたが、誤解を招くことがありました。

関連する問題