1

我们收到了来自用户的报告,称我们的谷歌课堂集成中的事情无法正常工作。在摸索了一下之后,我们让用户发送他们的 HAR 文件,其中包含他们使用我们的 API 时的所有网络信息。在其中我们发现我们提出的请求:

 gapi.client.request({
   root: 'https://classroom.googleapis.com',
   path: 'v1/courses',
   params: {
     'pageSize': 1,
     'teacherId': 'me'
   }
 })

返回带有 nextPageToken 属性集但没有课程属性集的响应。

以下是 HAR 文件中的实际条目(减去 Authorization 标头):

{
    "startedDateTime": "2016-03-25T21:08:16.672Z",
    "time": 957.9219999995985,
    "request": {
      "method": "GET",
      "url": "https://content-classroom.googleapis.com/v1/courses?pageSize=1&teacherId=me",
      "httpVersion": "unknown",
      "headers": [
        {
          "name": "X-Goog-Encode-Response-If-Executable",
          "value": "base64"
        },
        {
          "name": "X-Origin",
          "value": "https://www.lucidpress.com"
        },
        {
          "name": "X-ClientDetails",
          "value": "appVersion=5.0%20(X11%3B%20CrOS%20x86_64%207834.61.0)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F49.0.2623.95%20Safari%2F537.36&platform=Linux%20x86_64&userAgent=Mozilla%2F5.0%20(X11%3B%20CrOS%20x86_64%207834.61.0)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F49.0.2623.95%20Safari%2F537.36"
        },
        {
          "name": "User-Agent",
          "value": "Mozilla/5.0 (X11; CrOS x86_64 7834.61.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.95 Safari/537.36"
        },
        {
          "name": "Referer",
          "value": "https://content-classroom.googleapis.com/static/proxy.html?sensitive_query_string?"
        },
        {
          "name": "X-JavaScript-User-Agent",
          "value": "google-api-javascript-client/1.1.0-beta"
        },
        {
          "name": "X-Referer",
          "value": "https://www.lucidpress.com"
        }
      ],
      "queryString": [
        {
          "name": "pageSize",
          "value": "1"
        },
        {
          "name": "teacherId",
          "value": "me"
        }
      ],
      "cookies": [],
      "headersSize": -1,
      "bodySize": 0
    },
    "response": {
      "status": 200,
      "statusText": "",
      "httpVersion": "unknown",
      "headers": [
        {
          "name": "date",
          "value": "Fri, 25 Mar 2016 21:08:18 GMT"
        },
        {
          "name": "content-encoding",
          "value": "gzip"
        },
        {
          "name": "x-content-type-options",
          "value": "nosniff"
        },
        {
          "name": "server",
          "value": "ESF"
        },
        {
          "name": "x-frame-options",
          "value": "SAMEORIGIN"
        },
        {
          "name": "vary",
          "value": "Origin"
        },
        {
          "name": "vary",
          "value": "X-Origin"
        },
        {
          "name": "vary",
          "value": "Referer"
        },
        {
          "name": "content-type",
          "value": "application/json; charset=UTF-8"
        },
        {
          "name": "status",
          "value": "200"
        },
        {
          "name": "alternate-protocol",
          "value": "443:quic,p=1"
        },
        {
          "name": "cache-control",
          "value": "private"
        },
        {
          "name": "alt-svc",
          "value": "quic=\":443\"; ma=2592000; v=\"31,30,29,28,27,26,25\""
        },
        {
          "name": "content-length",
          "value": "198"
        },
        {
          "name": "x-xss-protection",
          "value": "1; mode=block"
        }
      ],
      "cookies": [],
      "content": {
        "size": 206,
        "mimeType": "application/json",
        "text": "{\n  \"nextPageToken\": \"some_string_token_sensitive?"\n}\n"
      },
      "redirectURL": "",
      "headersSize": -1,
      "bodySize": -1,
      "_transferSize": 448
    },
    "cache": {},
    "timings": {
      "blocked": 2.4730000004638,
      "dns": -1,
      "connect": -1,
      "send": 0.8660000003146702,
      "wait": 953.5609999984446,
      "receive": 1.0220000003754421,
      "ssl": -1
    }
  },

我已经让用户通过“试试看!”填写请求。api 描述中没有 pageSize 设置为 1 的区域,它会返回正确的格式。我们也无法使用我们的测试帐户进行复制,并且我们没有听到任何其他类似问题的报告。

有没有其他人遇到过这种情况或对可能发生的事情有任何想法?

4

1 回答 1

0

没有任何关于 JSON 响应的格式不正确。pageSize设置 API 应返回的最大结果数,而不是最小值。您的代码应该处理设置的情况,nextPageTokencourses不是通过检索下一页直到它返回课程。

出于好奇,您为什么只检索一门课程?

于 2016-03-26T13:38:12.430 回答