2

在語言部分我使用的是JavaScript。 由youtube v3提供的代碼示例適用於Web視圖(包含html + js),並且在鈦中,我不使用合金,我現在的代碼是鈦金屬經典應用程序。對於使用休息api我首先整合谷歌oauth然後調用上傳api它拋出錯誤提到下面,除了上傳api其他api的頻道列表,活動,搜索都工作正常。 錯誤拋出有時401/400/500取決於不同的命中和審判案件。youtube restapi(v3)整合鈦視頻上傳

`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) 

`

+0

'SSL = 0x532f08f8 cert_verify_callback主叫verifyCertificateChain authMethod = ECDHE_RSA' 總是收到這個錯誤 – 2015-03-16 13:25:39

+0

'HTTP:{ 「代碼」:-1, 「源」:{ 「位置」:「https://www.googleapis.com/upload/youtube/v3/videos?part = snippet%2CfileDetails&key =「xxx」,「status」:500,「」responseText「:」{\ n \「error \」:{\ n \「code \」:500 ,\ n \「message \」:null \ n} \ n「,」autoRedirect「:true,」connectionType「:」post「,」validatesSecureCertificate「:false,」statusText「:」內部服務器錯誤「, 「密碼」:空,「錯誤」:「內部服務器錯誤」,「成功」:false}' – 2015-03-16 14:05:10

回答

1

發現這個link &工作就像魅力的最後。