youtube restapi(v3)集成了钛金属视频上传

时间:2015-03-13 15:09:56

标签: javascript youtube-api titanium youtube-javascript-api youtube-data-api

在语言部分我正在使用javascript。     由youtube v3提供的代码示例用于Web视图(包含html + js),在钛合金中我不使用合金我的当前代码是钛经典应用程序。对于使用休息api我有第一个集成google oauth然后调用上传api它下面提出错误提示,除了上传api其他api频道列表,活动,搜索都工作正常。 错误抛出有时401/400 / 500取决于不同的命中和审判案例。

`var videofile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'phone.mp4');
        var args = {
                file : videofile.read(),
                description : 'test video'
        };
        var xhr = Ti.Network.createHTTPClient({
                    onload : function(e) {
                        try {                               
                            console.log(this.responseText);
                            var data = JSON.parse(this.responseText);
                            if (params.callback) {
                                params.callback(data);
                            } else {
                                for (var thing in data) {
                                    Ti.API.info("data." + thing + ' = ' + data[thing]);
                                }
                                Ti.API.warn("Data received but no callback specified.");
                            }

                        } catch(e) {
                            Titanium.UI.createAlertDialog({
                                title : 'Error',
                                message : 'Error accessing data: ' + JSON.stringify(e)

            });
                            Ti.API.error('RESPONSE: ' + JSON.stringify(e));
                        }
                    },
                    // function called when an error occurs, including a timeout
                    onerror : function(e) {
                        Titanium.UI.createAlertDialog({
                            title : 'Error',
                            message : 'Error accessing data: ' + JSON.stringify(e)
                        });
                        Ti.API.error('HTTP: ' + JSON.stringify(e));
                    },
                    timeout : 5000
                });
                console.log(propertyUrl);
                var urlString = "https://www.googleapis.com/upload/youtube/v3/videos?" + propertyUrl + "&key="+Titanium.App.Properties.getString('accessTokenGoogle'); 
                xhr.open("post",urlString);
                xhr.setRequestHeader("Authorization", "Bearer " + Titanium.App.Properties.getString('accessTokenGoogle'));
                ind.show();
                xhr.setRequestHeader('Content-Type', 'video/*');
                xhr.send(args); `

错误日志

`

[WARN] :   TiBaseFile: (KrollRuntimeThread) [8660,8660] Method is not supported org.appcelerator.titanium.io.TiResourceFile : getParent
[INFO] :   {"file":{"file":{"hidden":false,"nativePath":"file:///android_asset/Resources/phone.mp4","writable":false,"executable":false,"parent":null,"readonly":true,"directoryListing":[],"size":2076501,"apiName":"Ti.Proxy","name":"phone.mp4","symbolicLink":false,"bubbleParent":true},"nativePath":"file:///android_asset/Resources/phone.mp4","height":0,"length":2076501,"width":0,"mimeType":"video/mp4","apiName":"Ti.Blob","text":null,"type":1,"bubbleParent":true},"description":"test video"}
[INFO] :   urlSting ---> https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,contentDetails,fileDetails&key=ya29.OAFXEUm2kfyp39vdNB08nJt9Dswg_HTXBbOKXH97mSok-2rC2M233kEe8tOPrEUOPU8H-NUwZU8edQ
[INFO] :   I/System.out: propertyValue:true
[INFO] :   I/System.out: [socket][0] connection /74.125.130.95:443;LocalPort=46895(5000)
[INFO] :   I/System.out: [CDS]connect[/74.125.130.95:443] tm:5
[INFO] :   I/System.out: [socket][/192.168.0.188:46895] connected
[INFO] :   I/System.out: [CDS]rx timeout:5000
[ERROR] :  NativeCrypto: ssl=0x52982ec0 cert_verify_callback x509_store_ctx=0x54c69ab8 arg=0x0
[ERROR] :  NativeCrypto: ssl=0x52982ec0 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
[INFO] :   I/System.out: >doSendRequest
[INFO] :   I/System.out: <doSendRequest
[INFO] :   I/System.out: [CDS]close[46895]
[INFO] :   I/System.out: close [socket][/0.0.0.0:46895]
[WARN] :   IdleConnectionHandler: Removing a connection that never existed!
[ERROR] :  TiHttpClient: (TiHttpClient-1) [1393,10053] HTTP Error (org.apache.http.client.HttpResponseException): Internal Server Error
[ERROR] :  TiHttpClient: org.apache.http.client.HttpResponseException: Internal Server Error
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:275)
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:219)
[ERROR] :  TiHttpClient:    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
[ERROR] :  TiHttpClient:    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1334)
[ERROR] :  TiHttpClient:    at java.lang.Thread.run(Thread.java:838)

`

2 个答案:

答案 0 :(得分:1)

发现了link&amp;最终像魅力一样工作。

答案 1 :(得分:0)

如何使用此YouTube API模块?

https://github.com/quinn-madson/TiYouTubeAPI