在语言部分,我正在使用javascript。 youtube v3提供的代码示例适用于Web视图(包含HTML + js),在钛中我没有使用合金,我当前的代码是钛经典应用程序。对于使用 rest api,我首先集成了谷歌 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)
'
找到了这个链接,最后像魅力一样工作。
使用这个 YouTube API 模块怎么样?
https://github.com/quinn-madson/TiYouTubeAPI