longhornopen/canvas-api

Canvas API 的 PHP 客户端

v1.0.3 2023-09-28 15:01 UTC

This package is auto-updated.

Last update: 2024-08-28 19:01:55 UTC


README

PHP 库,用于通过其 API 与 Instructure 的 Canvas 进行通信。

Composer 安装

composer require longhornopen/canvas-api

使用示例

    use LonghornOpen\CanvasApi\CanvasApiClient;
    
    $api_host = 'myschool.instructure.com';
    $access_key = '1234567890abcdef....';
    $api = new CanvasApiClient($api_host, $access_key);
    
    // Some API calls return a single object, which will be given as a stdClass.
    $me = $api->get('/users/self');
    echo($me->name);
    
    // Some API calls return lists, which will be given as PHP7 Iterators.
    // If there are multiple pages of results, the iterator will automatically fetch them.
    $my_courses = $api->get('/courses?per_page=100');
    foreach ($my_courses as $my_course) {
        echo($my_course->name);
    }

    // Some API calls (e.g. Enrollment Terms) return lists which are wrapped in a wrapper element, which you can provide:
    $terms = $api->get('/accounts/1/terms', 'enrollment_terms');

版本历史

  • 1.0 - 公开发布