google 课堂公告创建 + php api(材料)

google classroom announcements create + php api (materials)

我正在使用 google 课堂 google API 和 Google APIs PHP 的客户端库。

可以加公告,但不能加资料

我想将文件添加到 Google 驱动器,但即使 "link" 我也有错误

到目前为止我的代码:

$client = new Google_Client();
$client->useApplicationDefaultCredentials();

$client->setApplicationName("test classroom");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/classroom.courses',
    "https://www.googleapis.com/auth/classroom.rosters",
    "https://www.googleapis.com/auth/classroom.announcements",
    "https://www.googleapis.com/auth/classroom.coursework.students",
    "https://www.googleapis.com/auth/classroom.coursework.me",
]);


// $service implements the client interface, has to be set before auth call
$service = new Google_Service_Classroom($client);

$text="some text";
$link="http://someurl";

$glink = new Google_Service_Classroom_Link($link);
$glink->setUrl($link);
$params = [
    "text" => $text,
    "materials" => [
        "link" => $glink,
    ],
];
$params_obj = new Google_Service_Classroom_Announcement($params);

$service->courses_announcements->create($course_classid, $params_obj);

//tried also with:
$params = [
    "text" => $text,
    "materials" => [
        "link" => ((new Google_Service_Classroom_Material())->setLink($glink)) ,
    ],
];

错误:

"message": "materials: Link materials must have a URL.",

最重要的是,您在这里创建 params 关联数组似乎很奇怪。 PHP 客户端具有添加所有参数的方法,一直到叶级别。所以你不应该在你的代码中看到任何数组。继续使用这些方法,这将有助于清理。如果您仍然遇到问题,我可能会花一些时间来深入研究这个特定项目。

Your limk must be array with three entry

$params = [
"text" => 'Please, do your homeworks until Monday',
"materials"=>['link'=>['url'=>'https://www.examaker.com', 
                     'title'=>'HW',
                      'thumbnailUrl'=>'https://examaker.com/apps/imgs/logo_40.png']
             ]
];