在 Outlook 日历上创建活动时遇到问题。超过 60 秒的最大执行时间 使用https://github.com/microsoftgraph/msgraph-sdk-php ..。如何解决此问题以克服超时错误并在 Outlook 上创建事件?
路线
Route::get('/graph', 'microsoftapi@createEvent');
microsoftapi 控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Jumbojett\OpenIDConnectClient;
use GuzzleHttp\Client;
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
class microsoftapi extends Controller
{
//
public $accessToken;
public function __construct()
{
$guzzle = new \GuzzleHttp\Client();
$tenantId = '***************';
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/token?api-version=1.0';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => "******************",
'client_secret' => "******************",
'resource' => 'https://graph.microsoft.com/',
'grant_type' => 'client_credentials',
],
])->getBody()->getContents());
$this->accessToken = $token->access_token;
}
public function createEvent(){
$data = [
'Subject' => 'Discuss the Calendar REST API',
'Body' => [
'ContentType' => 'HTML',
'Content' => 'I think it will meet our requirements!',
],
'Start' => [
'DateTime' => '2017-04-03T10:00:00',
'TimeZone' => 'Pacific Standard Time',
],
'End' => [
'DateTime' => '2017-04-03T11:00:00',
'TimeZone' => 'Pacific Standard Time',
],
];
$baseId = 'base-ID';
$calendarId = $baseId . 'calendar-ID';
$url = "/me/calendars/$calendarId/events";
$graph = new Graph();
$graph->setAccessToken($this->accessToken);
$graph->setProxyPort("localhost:8000");
$response = $graph->createRequest("POST", $url)
->attachBody($data)
->setReturnType(Event::class)
->execute();
dump($response);
}
}