首先,我尝试通过Android应用读取此视频中的字幕,但出现错误。
android studio上的错误
2019-08-23 14:52:03.305 10795-10825/com.yourpackgage.test E/Volley: [6358] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/youtube/v3/captions/wlxAjQEGnXSOcbGV3uyaE2bWv_WgY3UkzKJTfgrN5pU=?key=1111111
2019-08-23 14:52:03.306 10795-10795/com.yourpackgage.test W/salah: com.android.volley.ClientError
上面的密钥是假的
视频ID = oXGL0rsaNf8
有关此视频的JSON
{
"kind": "youtube#captionListResponse",
"etag": "\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/LfKWiWgO1cFVBuW-bhpK8cZ3BDk\"",
"items": [
{
"kind": "youtube#caption",
"etag": "\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/dNULxz5RgRO-NrDKDba68GyyHMQ\"",
"id": "wlxAjQEGnXSOcbGV3uyaE2bWv_WgY3UkzKJTfgrN5pU=",
"snippet": {
"videoId": "oXGL0rsaNf8",
"lastUpdated": "2019-08-22T20:32:51.346Z",
"trackKind": "ASR",
"language": "en",
"name": "",
"audioTrackType": "unknown",
"isCC": false,
"isLarge": false,
"isEasyReader": false,
"isDraft": false,
"isAutoSynced": false,
"status": "serving"
}
},
{
"kind": "youtube#caption",
"etag": "\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/sRhRzHkIfXoPqtkf34tollHS9hM\"",
"id": "o7LY5HsOVTDGtCHR21dw6ebewq9yCgjw6gw0GZ6OvtEEVN2s5vQgpw==",
"snippet": {
"videoId": "oXGL0rsaNf8",
"lastUpdated": "2019-08-23T01:37:49.403Z",
"trackKind": "standard",
"language": "en",
"name": "CC (English)",
"audioTrackType": "unknown",
"isCC": false,
"isLarge": false,
"isEasyReader": false,
"isDraft": false,
"isAutoSynced": false,
"status": "serving"
}
}
]
}
代码
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, "https://www.googleapis.com/youtube/v3/captions/wlxAjQEGnXSOcbGV3uyaE2bWv_WgY3UkzKJTfgrN5pU=?key=1111111", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.w("salah","done");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.w("salah",error.toString());
}
});
queue.add(request);
每次在排球库调用时遇到错误,我能知道我可以做什么来读取字幕。