我使用cordova构建应用程序,这个应用程序使用相机录制视频并上传到youtube(使用插件媒体捕获和文件传输),我一直在尝试Android和运行良好,但当我尝试在iOS上,这apps无法传递代码段参数,例如标题和说明。
这里是我的JS
var t = document.getElementById("title").value;
var d = document.getElementById("description").value;
var namef =document.getElementById("y_name").value;
var tipe =document.getElementById("y_tipe").value;
var urif = document.getElementById("y_url").value; //path from video recording
var searchurl = "https://www.googleapis.com/oauth2/v4/token";
$.ajax({
dataType: "json",
url: searchurl,
data: {
client_id: 'xxxx.apps.googleusercontent.com',
client_secret: 'xxxxx',
refresh_token: 'xxxxxxxx',
grant_type: 'refresh_token'
},
type: "POST",
contentType: "application/x-www-form-urlencoded;",
crossDomain: true,
cache: true,
success: function(data) {
alert(t); //showing alert from TITLE,and works at ios
var accessToken = data.access_token;
var options = new FileUploadOptions();
options.fileKey = 'file';
options.fileName = namef;
options.mimeType = tipe;
options.chunkedMode = false;
options.headers = {
Authorization: 'Bearer ' + accessToken
};
options.params = {
"": {
snippet: {
title: t,
description: d,
tags: 'Upload-Youtube-Test',
categoryId: 22
},
status: {
privacyStatus: 'public'
}
}
}; //here problem for iOS
var ft = new FileTransfer();
ft.upload(urif, 'https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,status', function(data) {
console.log(data.response);
},
function(e) {
console.log('upload error', e);
}, options, true);
ft.onprogress = function(data) {
var currentTime = Date.now();
var bytesUploaded = data.loaded;
var totalBytes = data.total;
var bytesPerSecond = bytesUploaded / ((currentTime - this.uploadStartTime) / 1000);
var estimatedSecondsRemaining = (totalBytes - bytesUploaded) / bytesPerSecond;
var percentageComplete = (bytesUploaded * 100) / totalBytes;
var progre = percentageComplete.toFixed();
console.log(progre);
};
},
});
}
,问题是
options.params = {
"": {
snippet: {
title: t,
description: d,
tags: 'Upload-Youtube-Test',
categoryId: 22
},
status: {
privacyStatus: 'public'
}
}
};
用于上传视频,是的,成功,此应用可以上传到youtube,但是youtube上的标题是未知的,这是来自片段传递的参数。这是Android的相同代码,但为什么iOS不起作用?即使我尝试静态标题和描述像这样:
options.params = {
"": {
snippet: {
title: 'Test Title',
description: 'Test Desc',
tags: 'Upload-Youtube-Test',
categoryId: 22
},
status: {
privacyStatus: 'public'
}
}
};
这个片段仍然无法传入youtube。