title: Google Script can't call Twitter API when using onEdit()
body: <p>I am trying to write a script which will pull data from twitter's API each time I edit a cell.  The demo code I currently have looks like this:</p>
  
  <pre><code>var ss    = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Candidates");
  
  function onEdit(e){
    var rng = e.range;
  
    // Check to make sure it is a single cell in specific column that was edited
    if(rng.getColumn() == 1 &amp;&amp; rng.getNumRows() == 1 &amp;&amp; rng.getNumColumns() == 1){
      callTwitter(rng.getRow());
    }
  }
  
  /* --- ---------------------- --- */
  /* --- Compare with core list --- */
  /* --- ---------------------- --- */
  function callTwitter(cRow){
    var cRow           = 2; // placeholder for testing
    var twitterService = getTwitterService();
    var response       = JSON.parse(twitterService.fetch('https://api.twitter.com/1.1/users/lookup.json?screen_name=' + sheet.getRange(cRow, 1, 1, 1).getValue()));
  
    sheet.getRange(cRow,2,1,1).setValue(response[0].screen_name);
  }
  </code></pre>
  
  <p><strong>What I've checked</strong></p>
  
  <ul>
  <li><p>I have confirmed that onEdit() gets called when I edit a cell and it does pass through the variable to the callTwitter() function.</p></li>
  <li><p>Running the callTwitter() function on its own returns the desired result (<em>pulls username from column A, queries twitter API and returns display name in column B</em>).</p></li>
  </ul>
  
  <p><strong>The issue</strong> </p>
  
  <p>The callTwitter() function always fails when I call it via the onEdit call.  It stops right before the following line of code.</p>
  
  <pre><code>var response       = JSON.parse(twitterService.fetch('https://api.twitter.com/1.1/users/lookup.json?screen_name=' + sheet.getRange(cRow, 1, 1, 1).getValue()));
  </code></pre>
  
  <p>My current assumption is that the onEdit call is somehow clashing with the API call, but I can't seem to find out why or how to solve it.</p>
  
  <p>--</p>
  
  <p>I have been trying to debug this for hours now and any help or direction on where to look would be very helpful.</p>
  
  <p>Code not included here is the Twitter OAuth which I copied from Google's example <a href="https://github.com/googlesamples/apps-script-oauth1" rel="nofollow noreferrer">https://github.com/googlesamples/apps-script-oauth1</a></p>