Trying to create a new project with files with an SDK on disk in Script applications.
Where exactly the request will follow UrlFetchApp...
{
"files": [
{
"id":"9basdfbd-749a-4as9b-b9d1-d64basdf803",
"name":"Code",
"type":"server_js",
"source":"function doGet() {\n return HtmlService.createHtmlOutputFromFile(\u0027index\u0027);\n}\n"
},
{
"id":"3asf7c0d-1afb-4a9-8431-5asdfc79e7ae",
"name":"index",
"type":"html",
"source":"\u003chtml\u003e\n \u003cbody\u003e\n New message!!\n \u003c/body\u003e\n\u003c/html\u003e"
}
]
}
This is from import / export documents and in the video example, Dan mentions that calls are for languages outside of Script applications, but requests a list of Script file types and the contents of these files work after authorization using the Eric oAuth2 library.
My last guess ...
function createProject( ) {
var token = getDriveService().getAccessToken();
var url = 'https://www.googleapis.com/upload/drive/v2/files?convert=true';
var files = {
"files": [
{
"name":"Code",
"type":"server_js",
"source":"function doGet() {\n return HtmlService.createHtmlOutputFromFile(\u0027index\u0027);\n}\n"
},
{
"name":"index",
"type":"html",
"source":"\u003chtml\u003e\n \u003cbody\u003e\n Hello, world!!\n \u003c/body\u003e\n\u003c/html\u003e"
}
]
};
var metadata = {
'title': 'script-test1',
'mimeType': 'application/vnd.google-apps.script',
"parents": [
{
"id": "0B2VkNbQMTnaCODBRVjZQcXBXckU"
}
],
};
var options = {
'headers' : {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/vnd.google-apps.script+json',
},
'method' : 'POST',
'payload' : files
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getResponseCode());
}
An unidentified Drive file of an unknown type is created, and the payload gets into it, but is not converted to the Script file type.
Switching to another route and just using ...
var file = {
"title": "Test script",
"mimeType": "application/vnd.google-apps.script",
"parents": [
{
"id": "[INSERT FOLDER ID HERE]"
}
]
};
Drive.Files.insert(file);
... throws an internal error.
, JS , , ( ) Script.