【发布时间】:2018-12-16 16:04:40
【问题描述】:
我正在使用 Dialogflow 创建 AI 助手,我需要使用 Google API(Google 日历和 gmail)。 API 运行良好(我使用了this as reference)。但是,当我将我的代码与 dialogflow webhook 集成时,它会返回 Webhook Call failed. Error: 500 Internal Server Error。
这是一个代码sn-p:
$client = new Google_Client();
$client->addScope(Google_Service_Gmail::GMAIL_READONLY); //view your emails and settings
$client->addScope(Google_Service_Gmail::GMAIL_COMPOSE); //manage drafts and send emails
$client->addScope(Google_Service_Gmail::GMAIL_MODIFY);
$client->addScope(Google_Service_Gmail::GMAIL_SEND); //send email on your behalf
$client->addScope(Google_Service_Calendar::CALENDAR); //manage calendar
$client->setAuthConfig('client_secret.json');
$client->setAccessType('offline');
$client->setApprovalPrompt('auto');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_SESSION['access_token']) && $_SESSION['access_token']){
$client->setAccessToken($_SESSION['access_token']);
$gmail = new Google_Service_Gmail($client);
$user = "emailaddress@gmail.com";
$calendar = new Google_Service_Calendar($client);
$intent = $json->queryResult->intent->displayName;
$location_any = $json->queryResult->parameters->location_any;
$text = $json->queryResult->parameters->text;
$name = $json->queryResult->parameters->name;
$choice = $json->queryResult->parameters->choice;
$subject = $json->queryResult->parameters->subject;
$location = $json->queryResult->parameters->location;
$description = $json->queryResult->parameters->description;
$startDateTime = $json->queryResult->parameters->startDateTime;
$endDateTime = $json->queryResult->parameters->endDateTime;
if($intent== "UnreadMessages"){
$unread = unReadMessages($gmail, $user);
$speech = "You have ".$unread." messages";
}
else if($intent == "GetSchedule"){
$events = get_event($calendar);
if($events){
$reply = "You have the following events coming up:";
foreach($events as $event){
$eventName = $event['eventName'];
$eventTime = $event['time'];
$reply .= $eventName."is at".$eventTime;
}
$speech = $reply;
}
else{
$speech = "You don't have any events coming up.";
}
}
}
我怀疑这可能是因为每次我尝试运行应用程序时都需要进行身份验证,因为只有在我检查会话令牌时才会开始弹出错误。我现在的问题是如何删除此身份验证过程?
【问题讨论】:
-
您能否更新您的问题以显示您“将其与 dialogflow webhook 集成”的代码?向我们展示服务器日志也可能指出错误所在。 “错误 500”通常表示服务器代码中存在语法错误。
-
刚刚添加了代码sn-p
标签: php google-api webhooks dialogflow-es