【问题标题】:google classroom announcements create + php api (materials)google课堂公告创建+php api(资料)
【发布时间】:2018-06-14 14:49:18
【问题描述】:

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

我可以添加公告,但我不能添加材料。

我想将文件添加到 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.",

【问题讨论】:

    标签: php google-api-php-client google-classroom


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      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']
                   ]
      ];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多