我当前正在处理需要与Outlook同步的日历。我正在使用Microsoft Graph API来这样做。在使用pool之前,我只是使用Guzzle的Promise / All发送要创建的所有事件,但是由于需要发送大量请求,因此我开始使用Pool。
从那时起,由于出现了此异常,我无法再发送请求:
#message: """
Client error: `POST https://graph.microsoft.com/v1.0/me/events` resulted in a `401 Unauthorized` response:\n
{\r\n
"error": {\r\n
"code": "InvalidAuthenticationToken",\r\n
"message": "Access token is empty.",\r\n
"innerError": (truncated...)\n
"""
#code: 401
我检查了,令牌在这里并发送。
-request: Request {#133 ▼
-method: "POST"
-requestTarget: null
-uri: Uri {#131 ▶}
-headers: array:4 [▼
"User-Agent" => array:1 [▶]
"Host" => array:1 [▶]
"headers" => array:3 [▼
"Authorization" => "Bearer EwBwA8l6BAAURSN/FHlDW5xN74t6GzbtsBBeBUYAAWTzMhExrArj8bNcA90meyaZFL2tGaUi/hMZwCHDmBldeTe1lQmKSaTqXXx/p3wEXqgP89QPu2+GISOcC5qctgaEISu7yrhpUlgd2U2XssPmFL5YW ▶"
"Content-Type" => "application/json"
"Prefer" => "outlook.timezone = "Romance Standard Time""
]
"json" => array:5 [▶]
]
-headerNames: array:4 [▶]
-protocol: "1.1"
-stream: Stream {#132 ▶}
我的应用程序的权限设置为:
Calendars.ReadWrite 委托和应用程序。 User.ReadWrite 委托和应用程序。
这是我的PHP代码
$requests_create = function ($batch, $accessToken){
foreach ($batch as $event){
yield new Request('POST', OUTLOOK_CALENDAR, [
'headers' => [
'Authorization' => 'Bearer '.$accessToken,
'Content-Type' => 'application/json',
'Prefer' => 'outlook.timezone = "Romance Standard Time"'
],
'json' => $event
]);
};
};
$pool_create = new Pool($client, $requests_create($events_outlook_create, $accessToken), [
'concurrency' => '5',
'fulfilled' => function ($response, $index){
dump($response);
},
'rejected' => function($reason, $index){
dump($reason);
}
]);
$promise = $pool_create->promise();
$promise->wait();
当我询问访问令牌时,这就是我从Azure中获得的信息:
{#79 ▼
+"token_type": "Bearer"
+"scope": "openid Calendars.ReadWr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