我需要更新 Exchange 中的用户自动回复(不在办公室)邮箱设置。我已准备好所有身份验证代码,并且可以正常工作。现在我只需要告诉我要更新什么。
C# 示例是:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var mailboxSettings = new MailboxSettings
{
AutomaticRepliesSetting = new AutomaticRepliesSetting
{
Status = AutomaticRepliesStatus.Scheduled,
ScheduledStartDateTime = new DateTimeTimeZone
{
DateTime = "2016-03-20T18:00:00",
TimeZone = "UTC"
},
ScheduledEndDateTime = new DateTimeTimeZone
{
DateTime = "2016-03-28T18:00:00",
TimeZone = "UTC"
}
}
};
var me = new User();
me.MailboxSettings = mailboxSettings;
await graphClient.Me
.Request()
.UpdateAsync(me);
我不确定如何使用 Graph API 将其转换为 PHP。我试图找到有关如何使用 PHP API 执行此操作的文档,但未成功。
这是我想出的PHP代码:
include "../../vendor/autoload.php";
$code=$_GET["code"];
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$oauthClient = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => "clientid",
'clientSecret' => "secret",
'redirectUri' => "redirect",
'urlAuthorize' => "auth",
'urlAccessToken' => "access",
'urlResourceOwnerDetails' => '',
'scopes' => 'offline_access MailboxSettings.ReadWrite'
]);
try {
// Make the token request
$accessToken = $oauthClient->getAccessToken('authorization_code', [
'code' => $code
]);
$token=$accessToken->getToken();
$graph = new Graph();
$graph->setAccessToken($token);
$user = $graph->createRequest('GET', '/me/mailboxSettings')
->setReturnType(Model\MailboxSettings::class)
->execute();
这段代码没有给我任何错误,但我不确定如何实际发送更新请求来更新设置。
另外,有没有办法让访问令牌持久化?我想要完成的是:用户输入休假请求,输入他们想要的外出消息。我会运行一个 cron 作业,当他们不在办公室时更新他们的不在办公室消息。那可能吗?