如何解决 类 中分配端点的错误请求?

How to resolve Bad Request on assignments endpoint in classes?

当我调用 Graph /assigments 端点时,我收到一个包含以下消息的错误请求:

Resource not found for the segment 'assignments'.

此代码模式适用于 /teachers/members 等其他端点,但不适用于 /assignments

代码:

$getEventsUrlAssignments = '/education/classes/' . $class->getId() . '/assignments';
try {
    $assignments = $graph->createRequest('GET', $getEventsUrlAssignments)
        ->setReturnType(Model\EducationAssignment::class)
        ->execute();
} 
catch (\GuzzleHttp\Exception\ClientException $e) {
    dd($e->getResponse()->getBody()->getContents());
}

我已经按照文档中的描述添加了正确的权限:

我可能做错了什么?

您收到此错误是因为 /assignments 仅在 Graph 的测试版中可用。如果您尝试使用 v1.0 调用此端点,Graph 将拒绝请求并出现以下错误:

{
    "error": {
        "code": "BadRequest",
        "message": "Resource not found for the segment 'assignments'.",
        "innerError": {
            "request-id": "38df490c-3a2b-4fe8-a77e-a7cce82831b5",
            "date": "2020-02-20T18:46:16"
        }
    }
}

为了使用 /assignments 端点,您需要调用测试版:

/beta/education/assignments/

您可以使用 setApiVersion:

告诉 SDK 使用 Beta 版本
$graph = new Graph();
$graph
  ->setBaseUrl("https://graph.microsoft.com/")
  ->setApiVersion("beta")
  ->setAccessToken($_SESSION['access_token']);

$getEventsUrlAssignments = '/education/classes/' . $class->getId() . '/assignments';
try {
    $assignments = $graph->createRequest('GET', $getEventsUrlAssignments)
        ->setReturnType(Model\EducationAssignment::class)
        ->execute();
} 
catch (\GuzzleHttp\Exception\ClientException $e) {
    dd($e->getResponse()->getBody()->getContents());
}

您还需要参考 Beta 模型,因为 v1.0 中没有分配模型。此过程在 Using Beta Models.

下的 SDK 的 Wiki 中进行了描述