YouTube API 3上传视频 - 无效凭据 - Android



我正在研究一个记录视频的Android应用程序,并允许用户使用YouTube数据API V3直接上传到YouTube。该代码类似于:

中描述的代码

YouTube API 3上传视频 - 访问未配置 - Android

在大多数情况下,它成功地将文件上传到YouTube,但是,当文件非常大(录像〜小时,几个GB数据)时,上传会失败。上传通过4GB文件达到一半,然后产生此消息:

{
    "code": 401,
    "errors": [
        {
            "domain": "global",
            "location": "Authorization",
            "locationType": "header",
            "message": "Invalid Credentials",
            "reason": "authError"
        }
    ],
    "message": "Invalid Credentials"
}

成功的代码和不成功的代码之间没有变化。凭证是相同的。上载在失败之前工作了大约一个小时。

在Android StackTrace中找到了其他潜在有用的信息:

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) {
    ...
}

有一个已知的问题,关于重新上传的上传超过一个小时。

您可以从问题跟踪器中跟踪问题的进度:

https://code.google.com/p/gdata-issues/issues/detail?id=5124

看起来您的上传所花费的时间超过了访问令牌剩下的一小时(或更少)。

我不知道客户库是否如何处理到期的令牌,因此您可能需要在ProgressListener中自己处理。

相关内容

  • 没有找到相关文章

最新更新