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

时间:2014-01-20 16:14:34

标签: android youtube youtube-api oauth-2.0 google-oauth

我正在开发一款能够录制视频的Android应用,并允许用户使用YouTube Data API v3将其直接上传到YouTube。代码类似于:

中描述的代码

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

2 个答案:

答案 0 :(得分:0)

看起来您的上传时间超过了访问令牌生效的一小时(或更短时间)。

我不知道客户端库是否/如何处理过期令牌,因此您可能希望自己在progressListener中处理它。

答案 1 :(得分:0)

关于可恢复上传失败超过一小时的已知问题。

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

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