title: Google Visualization API Query fails with new Google Spreadsheets
body: <p>I work for a Google Apps Reseller and I implement gadgets for our clients.</p>
  
  <p>We have several gadgets that use Google Visualization API to query a spreadsheet (with a dynamic id) and display the result in a table.</p>
  
  <p>We are using this piece of code:</p>
  
  <pre><code>function drawVisualization() {
    var oldSpreadsheetUrl = "https://docs.google.com/spreadsheet/tq?key=&lt;ss_id&gt;";
    var newSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/&lt;ss_id&gt;/gviz/tq";
    var query = new google.visualization.Query(oldSpreadsheetUrl);
    query.setQuery("SELECT A,B");
    query.send(handleQueryResponse);
  }
  
  function handleQueryResponse(response) {
    if(response.isError()) {
      console.log(response.getMessage());
    } else {
      console.log("NUMBER OF COLUMNS: " + response.getDataTable().getNumberOfColumns());
    }
  }
  </code></pre>
  
  <p>And testing with this sample spreadsheet (New Google Spreadsheet)</p>
  
  <p><strong>SPREADSHEET ID</strong>: 1qMvY3y4MkwoK1UvCA9A8dW4BbmhH1iMwWqGLEM5vjJk</p>
  
  <hr>
  
  <p>As long as we query an old spreadsheet everything works ok, but if we query a new spreadsheet (with the standard url - <code>oldSpreadsheetUrl</code>) the request fails with a timeout exception and we get a 404 exception.
  This is the message we get in the Browser Console:
  <a href="http://i.imgur.com/h4DjyQ6.png" rel="nofollow">http://i.imgur.com/h4DjyQ6.png</a></p>
  
  <p>We were able to make the query work anyway, by using this new url in the datasource:</p>
  
  <pre><code>"https://docs.google.com/spreadsheets/d/&lt;spreadsheet_id&gt;/gviz/tq"
  </code></pre>
  
  <p>But with this notation the setQuery directive is ignored and all of the three columns are returned instead of the first two (<code>"SELECT A,B"</code>).</p>
  
  <p>We are using this in several gadgets and therefore want to know:</p>
  
  <ol>
  <li>How can we overcome the <code>setQuery</code> bug?</li>
  <li>Is there a programmatic way to know if a spreadsheet is a new version or an old version?</li>
  </ol>
  
  <p>Thank you in advance.</p>
  
  <p>Regards,</p>
  
  <p>Riccardo</p>