无法添加到其他用户的日历 [英] Cannot add to another users calendar

查看:149
本文介绍了无法添加到其他用户的日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试允许用户将项目添加到其他用户的日历中. 用户登录并按以下方式获取令牌

I am attempting to allow a user add items to the calendars of other users. A user logs in and get the token as follows

const AUTHORIZE_ENDPOINT = '/oauth2/v2.0/authorize';
const TOKEN_ENDPOINT     = '/oauth2/v2.0/token';
const SCOPES             = 'profile openid email User.Read Calendars.ReadWrite Calendars.Read Calendars.Read.Shared Calendars.ReadWrite Calendars.ReadWrite.Shared';


$graph = new Graph();
$graph->setAccessToken($token);
$response = $graph->createRequest("GET", "/me")->setReturnType(Model\User::class)->execute(); 

已登录的用户可以使用

$request = $graph->createRequest("post", '/me/events');
$request->attachBody($data);
$response = $request->execute(); 

但是,当我尝试使用

$request = $graph->createRequest("post", '/anotheruser/events');
$request->attachBody($data);
$response = $request->execute(); 

我收到消息

Resource not found for the segment

已获得管理员身份验证同意,所以一切都很好.

Have done the admin auth consent, so all should be fine.

有什么建议吗?

推荐答案

如果要访问其他用户的数据,则必须使用以下网址:

If you want to access another user's data you have to use the following url:

/users/{id | userPrincipalName}

您的请求格式错误,您最终向不存在的资源发送了请求,因此Graph不知道该怎么办.
就您而言,您只需要在/users前面添加(有关更多信息,请参见

Your request was just in the wrong form and you ended up sending a request to an non existing resource, thus Graph didn't know what to do.
In your case you just need to prepend /users (for more information see documentation).

因此您的请求可能如下所示:

So your request could look like this:

$request = $graph->createRequest("post", '/users/anotheruser/events');

请记住,如果您以用户身份登录(令牌),则您尝试访问的日历必须已与登录用户共享.否则,由于缺少权限,它将失败,因为Graph只允许编辑日历.您还需要权限Calendars.Read.Shared和/或Calendars.ReadWrite.Shared(您似乎已经拥有).
如果您获得没有用户,则无需共享日历然后,您将自动拥有对所有用户的完全访问权限.

Keep in mind that if you are logged in as a user (token on behalf of a user), the calendar you try to access to must have been shared with the logged in user. Otherwise it will fail due to missing privileges as Graph only allows to edit Calendars that are shared with the user. You also need the Permissions Calendars.Read.Shared and/or Calendars.ReadWrite.Shared (which you seem to already have aquired).
Calendar sharing is unnecessary if you gain access without a user as you then automatically have full access to all users.

当前,Graph API仅支持访问共享的日历,但不支持编辑/更改共享状态或查看与用户共享哪些日历的操作.但是,您可以在Outlook或Powershell上手动更改共享状态.

Currently the Graph API only supports access to shared Calendars but no operations to edit/change the sharing status or see which Calendars are shared with a user. However you can change the sharing status manually over outlook or the powershell.

这篇关于无法添加到其他用户的日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆