现在我的谷歌教室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 = ["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);
}
答案 0 :(得分:0)
我无法确认Google API的Javascript客户端是否已具有Classroom API功能(因为它仍然处于测试阶段),但您可以尝试调用
gapi.client [教室/ classroom.courses] .courseWork.list({..参数..},函数(){...回调...});
或者,直接在Javascript中调用REST API,而不使用JS客户端。