Google Apps脚本驱动器错误

时间:2014-02-05 16:36:31

标签: javascript google-apps-script google-drive-api

这是我关于SO的第一篇文章,所以我希望我能正确地做到这一点。我有一个Google Apps脚本用作Web挂钩,用于在两个服务之间创建集成:YouCanBook.Me和Taleo。该脚本作为Web应用程序发布,具有“任何人,甚至是匿名”访问权限,并且已经工作了数周。最近(截至2014年3月3日,我相信)它停止工作,现在导航到公共URL导致以下错误消息:

  

Google云端硬盘遇到错误。如果重新加载页面没有帮助,请报告错误。

     

要详细了解Google云端硬盘,请访问我们的帮助中心。

     

对于给您带来的不便,我们深表歉意。谢谢你的帮助!    - Google云端硬盘小组

以下是整个脚本的代码:

function doGet(request) {

  try {
    //Get token data from URL parameters
    var candidateID = request.parameter.candID;
    var requisitionID = request.parameter.reqID;
    var interviewType = request.parameter.intType;
    var requestType = request.parameter.request;
  }
  catch(e) {
    Logger.log('Unable to capture required parameters.  Error message: ' + e);
    return;
  }

  //Get authToken by passing in credentials
  var authToken = taleoLogin();

  //Get candidate application ID
  var candidateApplicationID = getCandidateApplicationID(authToken, candidateID, requisitionID);

  //Make PUT request to change candidate's status
  taleoSubmit(authToken, candidateID, requisitionID, candidateApplicationID, interviewType, requestType);

  //Logout
  taleoLogout(authToken);
}



function getCandidateApplicationID(authToken, candidateID, requisitionID) {
  //Build API call
  var loginURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/object/candidateapplication?candidateId=' + candidateID + '&requisitionId=' + requisitionID;
  var loginOptions = {
    'method' : 'get',
    'headers' : {
      'cookie' : authToken
    },
    'contentType' : 'application/json; charset=utf-8'
  };

  //Make API call
  try {
    var loginResponse = UrlFetchApp.fetch(loginURL, loginOptions);
    if (loginResponse.getResponseCode() == 200) {
      Logger.log('Logged in!');
    }
    else {
      Logger.log('Error logging in: ' + loginResponse.getContentText());
    }
  }
  catch (e) {
    Logger.log('Could not log in: ' + e);
  }

  //Return candidate application ID
  return candidateApplicationID = JSON.parse(loginResponse).response.candtoreqs[0].candidateapplication.id.toFixed(0);
}



//-----------------------------------//
//  Log into Taleo via the REST API  //
//-----------------------------------//

function taleoLogin() {
  //Build API call
  var loginURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/login?orgCode=[companyCode]&userName=[username]&password=[password]';
  var loginOptions = {
    'method' : 'post',
    'contentType' : 'application/json'
  };

  //Make API call
  try {
    var loginResponse = UrlFetchApp.fetch(loginURL, loginOptions);
    if (loginResponse.getResponseCode() == 200) {
      Logger.log('Logged in!');
    }
    else {
      Logger.log('Error logging in: ' + loginResponse.getContentText());
    }
  }
  catch (e) {
    Logger.log('Could not log in: ' + e);
  }

  //Return full authToken key
  return authToken = 'authToken=' + JSON.parse(loginResponse).response.authToken;
}


//-------------------------------------//
//  Log out of Taleo via the REST API  //
//-------------------------------------//

function taleoLogout(authToken) { 
  //Build API call
  var logoutURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/logout';
  var logoutOptions = {
    'method' : 'post',
    'headers' : {
      'cookie' : authToken
    },
    'contentType' : 'application/json; charset=utf-8'
  };

  //Make API call
  try {
    var logoutResponse = UrlFetchApp.fetch(logoutURL, logoutOptions);
    if (logoutResponse.getResponseCode() == 200) {
      Logger.log('Logged out!');
    }
    else {
      Logger.log('Error logging out: ' + logoutResponse.getContentText()); 
    }
  }
  catch (e) {
    Logger.log('Could not log out: ' + e); 
  }
}


//-----------------------------------------//
//  Submit data to Taleo via the REST API  //
//-----------------------------------------//

function taleoSubmit(authToken, candID, reqID, appID, intType, requestType) {

  //If phone interview and initial booking
  if(intType == 'phone' && requestType == 'booking') {
    //Build API call
    try {
      var submitURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/object/candidateapplication/' + appID;
      var payload = JSON.stringify({ "candidateapplication" : { "candidateId" : candID, "requisitionId" : reqID, "status" : 5033 }});
      var submitOptions = {
        'method' : 'put',
        'headers' : {
          'cookie' : authToken
        },
        'contentType' : 'application/json; charset=utf-8',
        'payload' : payload
      };
    }
    catch (e) {
      Logger.log('Error creating API call: ' + e); 
    }
  }
  else if(intType == 'final' && requestType == 'booking') {
    //Build API call
    try {
      var submitURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/object/candidateapplication/' + appID;
      var payload = JSON.stringify({ "candidateapplication" : { "candidateId" : candID, "requisitionId" : reqID, "status" : 5048 }});
      var submitOptions = {
        'method' : 'put',
        'headers' : {
          'cookie' : authToken
        },
        'contentType' : 'application/json; charset=utf-8',
        'payload' : payload
      };
    }
    catch (e) {
      Logger.log('Error creating API call: ' + e); 
    }
  }
  else if(intType == 'phone' && requestType == 'cancel') {
    //Build API call
    try {
      var submitURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/object/candidateapplication/' + appID;
      var payload = JSON.stringify({ "candidateapplication" : { "candidateId" : candID, "requisitionId" : reqID, "status" : 5032 }});
      var submitOptions = {
        'method' : 'put',
        'headers' : {
          'cookie' : authToken
        },
        'contentType' : 'application/json; charset=utf-8',
        'payload' : payload
      };
    }
    catch (e) {
      Logger.log('Error creating API call: ' + e); 
    }
  }
  else if(intType == 'final' && requestType == 'cancel') {
    //Build API call
    try {
      var submitURL = 'https://ch.tbe.taleo.net/CH06/ats/api/v1/object/candidateapplication/' + appID;
      var payload = JSON.stringify({ "candidateapplication" : { "candidateId" : candID, "requisitionId" : reqID, "status" : 5047 }});
      var submitOptions = {
        'method' : 'put',
        'headers' : {
          'cookie' : authToken
        },
        'contentType' : 'application/json; charset=utf-8',
        'payload' : payload
      };
    }
    catch (e) {
      Logger.log('Error creating API call: ' + e); 
    }
  }

  //Make API call
  try {
    var submitResponse = UrlFetchApp.fetch(submitURL, submitOptions);
    if (submitResponse.getResponseCode() == 200) {
      Logger.log('Results submitted!');
    }
    else {
      Logger.log('Error submitting results: ' + submitResponse.getContentText());
    }
  } 
  catch (e) {
    Logger.log('Could not submit results: ' + e); 
  }
}

0 个答案:

没有答案