[英]Batch requests with Google's Client Library with Javascript
I'm trying to request multiple records using google's client library api. 我正在尝试使用谷歌的客户端库api请求多个记录。 I'm attempting to get a list of students and a separate list of assignments that are affiliated with a single google class.
我正在尝试获取学生列表以及与单个Google课程相关联的单独作业列表。 I'm using the google classroom api ( https://developers.google.com/classroom/reference/rest/ ).
我正在使用谷歌教室api( https://developers.google.com/classroom/reference/rest/ )。
Here's what I've got so far: 这是我到目前为止所得到的:
let batch = gapi.client.newBatch();
let courseWorkRequest = function(courseId) {
return gapi.client.request({
'path': `/v1/courses/${courseId}/courseWork`,
});
};
let studentRequest = function (courseId) {
return gapi.client.request({
'path': `/v1/courses/${courseId}/students`
});
};
listOfGoogleClasses.forEach(function (course) {
let courseAssignments = courseWorkRequest(course.id);
batch.add(courseAssignments);
let courseStudents = studentRequest(course.id);
batch.add(courseStudents)
});
batch.then(function(response){
console.log(response);
});
The request works but for the response, I'm just getting a series of objects that look like so: 请求有效,但对于响应,我只是得到一系列看起来像这样的对象:
body:"Not Found"
headers:Object
result:false
status:404
statusText: "Not Found"
Deducing from the error itself, it means you're missing some required properties of the request body like Content-Type, Content-Length, etc. The example can be seen in Example batch request 从错误本身中推断,这意味着您缺少请求体的一些必需属性,如Content-Type,Content-Length等。示例可以在示例批处理请求中看到
POST https://classroom.googleapis.com/batch HTTP/1.1
Authorization: Bearer your_auth_token
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
Content-Transfer-Encoding: binary
MIME-Version: 1.0
Content-ID: <item1:12930812@classroom.example.com>
PATCH /v1/courses/134529639?updateMask=name HTTP/1.1
Content-Type: application/json; charset=UTF-8
Authorization: Bearer your_auth_token
{
"name": "Course 1"
}
--batch_foobarbaz
Content-Type: application/http
Content-Transfer-Encoding: binary
MIME-Version: 1.0
Content-ID: <item2:12930812@classroom.example.com>
PATCH /v1/courses/134529901?updateMask=section HTTP/1.1
Content-Type: application/json; charset=UTF-8
Authorization: Bearer your_auth_token
{
"section": "Section 2"
}
The google client library is for all Google APIs. Google客户端库适用于所有Google API。 Therefore I think you need to provide the full URL in the path.
因此,我认为您需要在路径中提供完整的URL。
Try setting path to: https://classroom.googleapis.com/v1/courses/{courseId}/courseWork
instead of just /v1/courses/{courseId}/courseWork
尝试设置路径:
https://classroom.googleapis.com/v1/courses/{courseId}/courseWork
: /v1/courses/{courseId}/courseWork
而不仅仅是/v1/courses/{courseId}/courseWork
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.