我正在使用谷歌课堂谷歌API和谷歌API客户端库PHP。
我可以添加公告,但我无法添加材料。
我想将文件添加到Google云端硬盘,但即使使用"链接"我也有错误
到目前为止我的代码:
$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.",
答案 0 :(得分:0)
所以在顶部,你在创建params关联数组似乎很奇怪。 PHP客户端具有添加所有参数的方法,一直到叶级别。所以你不应该在你的代码中看到任何数组。继续使用这些方法,它将有助于清理。如果你还有问题,我可能有时间去挖掘这个特定的项目。
答案 1 :(得分:-1)
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']
]
];