Javascript谷歌课堂API-获取课程作业
现在,我有谷歌课堂API,可以很好地获取我所学的每门课程的名称和部分。我想把每门课的家庭作业都列在一张单子上。我该怎么做 我目前有:Javascript谷歌课堂API-获取课程作业,javascript,api,google-classroom,Javascript,Api,Google Classroom,现在,我有谷歌课堂API,可以很好地获取我所学的每门课程的名称和部分。我想把每门课的家庭作业都列在一张单子上。我该怎么做 我目前有: // Your Client ID can be retrieved from your project in the Google // Developer Console, https://console.developers.google.com var CLIENT_ID = '<CLIENTID>'; var SCOPES =
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = '<CLIENTID>';
var SCOPES = ["https://www.googleapis.com/auth/classroom.courses.readonly"];
/**
* Check if current user has authorized this application.
*/
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, handleAuthResult);
}
/**
* Handle response from authorization server.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
loadClassroomApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* @param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthResult);
return false;
}
/**
* Load Classroom API client library.
*/
function loadClassroomApi() {
gapi.client.load('classroom', 'v1', listCourses);
}
/**
* Print the names of the first 10 courses the user has access to. If
* no courses are found an appropriate message is printed.
*/
function listCourses() {
var request = gapi.client.classroom.courses.list({
pageSize: 10
});
request.execute(function(resp) {
var courses = resp.courses;
if (courses.length > 0) {
for (i = 0; i < courses.length; i++) {
var course = courses[i];
var div = document.createElement('div');
div.className = 'class="col-md-4"';
div.innerHTML = '<div class="col-md-4"> \
<div class="jumbotron"> \
<h2>' + course.name + '</h2> \
<p>' + course.section + '</p> \
</div> \
</div> \
</div>';
document.getElementById('output').appendChild(div);
}
} else {
appendPre('No courses found.');
}
});
}
/**
* Append a pre element to the body containing the given message
* as its text node.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
//您的客户端ID可以从Google中的项目中检索
//开发者控制台,https://console.developers.google.com
var客户端ID=“”;
变量作用域=[”https://www.googleapis.com/auth/classroom.courses.readonly"];
/**
*检查当前用户是否已授权此应用程序。
*/
函数checkAuth(){
gapi.auth.authorize(
{
“客户id”:客户id,
“scope”:SCOPES.join(“”),
“立即”:真
},handleAuthResult);
}
/**
*处理来自授权服务器的响应。
*
*@param{Object}authResult授权结果。
*/
函数handleAuthResult(authResult){
var authorizeDiv=document.getElementById('authorized-div');
if(authResult&!authResult.error){
//隐藏身份验证UI,然后加载客户端库。
authorizeDiv.style.display='none';
loadClassroomApi();
}否则{
//显示授权UI,允许用户通过
//单击“授权”按钮。
authorizeDiv.style.display='inline';
}
}
/**
*响应用户单击“授权”按钮,启动身份验证流。
*
*@param{Event}Event按钮单击事件。
*/
函数handleAuthClick(事件){
gapi.auth.authorize(
{client_id:client_id,scope:SCOPES,immediate:false},
手工(结果);
返回false;
}
/**
*加载教室API客户端库。
*/
函数loadClassroomApi(){
gapi.client.load('教室','v1',列表课程);
}
/**
*打印用户有权访问的前10门课程的名称。如果
*未找到课程,将打印相应的消息。
*/
功能列表课程(){
var request=gapi.client.教室.courses.list({
页面大小:10
});
请求执行(功能(resp){
var课程=相应课程;
如果(课程长度>0){
对于(i=0;i
我无法确认Google API的Javascript客户端是否已经具备教室API功能(因为它仍处于测试阶段),但您可以尝试调用
gapi.client.[classket/classket.courses].courseWork.list({..parameters..},function(){…callback…})
或者,直接在Javascript中调用,而不使用JS客户端。即使我可以完成作业,您是否遵循了quickstart()中的所有步骤?你会因为一个错误得到什么?或者什么似乎不起作用?我不知道该把什么放在哪里。@Wade73课程作业部分不太清楚。这里没有实际的代码。这里的示例只针对PythonOK,我将看一看