我正在開發一款Android應用程序,該應用程序可以記錄視頻並允許用戶使用YouTube Data API v3直接將其上傳到YouTube。該代碼是類似於描述:YouTube API 3上傳視頻 - 無效憑證 - Android
YouTube API 3 Upload Video - Access not configured - Android
它成功地上傳文件到YouTube在大多數情況下,然而,當該文件是非常大的(〜鏡頭小時,幾個GB的數據),上傳失敗。上傳達到約通過4GB的文件的一半,然後生成此消息:
{
"code": 401,
"errors": [
{
"domain": "global",
"location": "Authorization",
"locationType": "header",
"message": "Invalid Credentials",
"reason": "authError"
}
],
"message": "Invalid Credentials"
}
還有就是成功和失敗的代碼之間沒有變化。憑證是一樣的。上傳失敗前大約一個小時。
其它潛在有用的信息,在Android堆棧跟蹤發現:
W/GLSUser(1794): [amz][amz] Permission for com.package.name to access oauth2: https://www.googleapis.com/auth/youtube.upload will be managed remotely.
W/qdhwcomposer(318): Excessive delay reading vsync: took 1182 ms
W/HttpTransport(8543): exception thrown while executing request
W/HttpTransport(8543): java.io.IOException: unexpected end of stream
W/HttpTransport(8543): at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
W/HttpTransport(8543): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81)
W/HttpTransport(8543): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:964)
W/HttpTransport(8543): at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:559)
W/HttpTransport(8543): at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:434)
W/HttpTransport(8543): at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:345)
W/HttpTransport(8543): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:418)
W/HttpTransport(8543): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
W/HttpTransport(8543): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
W/HttpTransport(8543): at com.multplx.android.trickbook.uploader.VideoUploadAsyncTask.doInBackground(VideoUploadAsyncTask.java:133)
W/HttpTransport(8543): at com.multplx.android.trickbook.uploader.VideoUploadAsyncTask.doInBackground(VideoUploadAsyncTask.java:1)
W/HttpTransport(8543): at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/HttpTransport(8543): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
W/HttpTransport(8543): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/HttpTransport(8543): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/HttpTransport(8543): at java.lang.Thread.run(Thread.java:841)
W/VideoUploadAsyncTask(8543): @ Exception : com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
對應於:
try {
// https://developers.google.com/youtube/v3/docs/videos/insert
Insert videoInsert = inserts[0];
uploader = videoInsert.getMediaHttpUploader();
uploader.setProgressListener(progressListener);
Video returnedVideo = videoInsert.execute();
} catch (IOException ioe) {
...
}