title: Google Analytics Data in Google Spreadsheets
body: <p>I am able to get the code example to work pulling in data from Google Analytics into Google Spreadsheet (<a href="https://developers.google.com/analytics/solutions/articles/reporting-apps-script" rel="nofollow">https://developers.google.com/analytics/solutions/articles/reporting-apps-script</a>)   However, I know the ID of the profile I want, I don't need to go through the overhead of getting the "first profile."  I can't get it working when I try to hard code an ID like this:
  </p>
  
  <pre class="lang-js prettyprint-override"><code>function getReportDataForProfile() {
  
    var profileId = '12345678';
    var tableId = 'ga:12345678';
    var startDate = getLastNdays(14);   // 2 weeks (a fortnight) ago.
    var endDate = getLastNdays(0);      // Today.
  
    var optArgs = {
      'dimensions': 'ga:keyword',              // Comma separated list of dimensions.
      'sort': '-ga:visits,ga:keyword',         // Sort by visits descending, then keyword.
      'segment': 'dynamic::ga:isMobile==Yes',  // Process only mobile traffic.
      'filters': 'ga:source==google',          // Display only google traffic.
      'start-index': '1',
      'max-results': '250'                     // Display the first 250 results.
    };
  
    // Make a request to the API.
    var results = Analytics.Data.Ga.get(
        tableId,                  // Table id (format ga:xxxxxx).
        startDate,                // Start-date (format yyyy-MM-dd).
        endDate,                  // End-date (format yyyy-MM-dd).
        'ga:visits,ga:pageviews', // Comma seperated list of metrics.
        optArgs);
  
    if (results.getRows()) {
      return results;
  
    } else {
      throw new Error('No profiles found');
    }
  }
  </code></pre>