Api Google应用程序脚本Basecamp从anothr项目创建附件
我想把附件从一个项目复制到另一个已经在basecamp上有附件的项目这里是我正在使用的代码 我在创建附件时遇到的问题我可以上载附件集,但无法使用正确的文件内容创建附件创建的文件内容错误,在我尝试操作时返回无效文件 我用过这个 谢谢Api Google应用程序脚本Basecamp从anothr项目创建附件,api,google-apps-script,basecamp,Api,Google Apps Script,Basecamp,我想把附件从一个项目复制到另一个已经在basecamp上有附件的项目这里是我正在使用的代码 我在创建附件时遇到的问题我可以上载附件集,但无法使用正确的文件内容创建附件创建的文件内容错误,在我尝试操作时返回无效文件 我用过这个 谢谢 function copyAttachements() { sourceProjectID=4683117; destinationProjectID=4683125; var url=getProjectURL(sourceP
function copyAttachements()
{
sourceProjectID=4683117;
destinationProjectID=4683125;
var url=getProjectURL(sourceProjectID);
var unamepass=username+":"+password ;
var digest = Utilities.base64Encode(unamepass);
var digestfull = "Basic "+digest;
var header={Authorization: digestfull};
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
if(String(response.getResponseCode())=="200")
{
var name,content;
url=url.replace(".json","/attachments.json");
var header={Authorization: digestfull};
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
var jsonData=Utilities.jsonParse(response.getContentText());
for(var j in jsonData)
{
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
content=UrlFetchApp.fetch(url,option).getContent();
var url = "https://basecamp.com/"+BasecampID+"/api/v1/attachments.json";//getProjectURL(destinationProjectID);
var data={"content": content,"Content-Length":jsonData[j].byte_size,"Content-Type":jsonData[j].content_type};
var header={Authorization: digestfull};
var payload = JSON.stringify(data);
var option={ method : "post",muteHttpExceptions:true,headers : header,payload:payload,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
var url =getProjectURL(destinationProjectID);
url=url.replace(".json","/uploads.json");
var header={Authorization: digestfull};
var data={"content": jsonData[j].content,
"attachments": [{"token": Utilities.jsonParse(response.getContentText()).token, "name": jsonData[j].name}]};
var payload = JSON.stringify(data);
var option={ method : "post",muteHttpExceptions:true,headers : header,payload:payload,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
}
}
else
Browser.msgBox("Error",response);
}
function copyAttachements()
{
sourceProjectID=4683117;
destinationProjectID=4683125;
var url=getProjectURL(sourceProjectID);
var unamepass=username+":"+password ;
var digest = Utilities.base64Encode(unamepass);
var digestfull = "Basic "+digest;
var header={Authorization: digestfull};
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
if(String(response.getResponseCode())=="200")
{
var name,content;
url=url.replace(".json","/attachments.json");
var header={Authorization: digestfull};
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
var jsonData=Utilities.jsonParse(response.getContentText()).reverse();
for(var j in jsonData)
{
url=jsonData[j].url;
var option={ method : "get",muteHttpExceptions:true,headers : header,contentType : "application/json"};
/**********************Changes Done here*********************************/
content=UrlFetchApp.fetch(url,option).getContent();
var url ="https://basecamp.com/"+BasecampID+"/api/v1/attachments.json";
var header={Authorization: digestfull};
var option={ method : "post",muteHttpExceptions:true,headers : header,payload:content,contentType : jsonData[j].content_type};
/***********************************************************************/
var response=UrlFetchApp.fetch(url,option);
var url =getProjectURL(destinationProjectID);
url=url.replace(".json","/uploads.json");
var header={Authorization: digestfull};
var token=Utilities.jsonParse(response.getContentText()).token
var data={"attachments": [{"token":token, "name": jsonData[j].name}]};
var payload = JSON.stringify(data);
var option={ method : "post",muteHttpExceptions:true,headers : header,payload:payload,contentType : "application/json"};
var response=UrlFetchApp.fetch(url,option);
}
}
else
Browser.msgBox("Error",response);
}